c# - How to access one WCF service from another? -


actually having 2 service, service , service b. trying call service service b (like said got proxy classes , calling). problem when access service "postman rest client packaged app" or "mobile" not working. client("postman rest client packaged app" or "mobile") service calling fine service can't call service b.(the remote server returned unexpected response: (400) bad request). if try access service using dll in console application , calling service a. time service can call service b working fine.

    service a:     [servicecontract]     public interface iuserprofilefacedservice     {         [webinvoke(method = "post", responseformat = webmessageformat.json, requestformat = webmessageformat.json, bodystyle = webmessagebodystyle.wrapped, uritemplate = "getresult")]         string getresult(int64 userid,string str1,string str2,string str3);     }      public class servicea : basefacedservice, iservicea     {         public string getresult(int64 userid,string str1,string str2,string str3)         {             channelfactory<iservice> factory = new channelfactory<iservice>("webhttpbinding_servicereference2");             iservice client = factory.createchannel();             string responce = client.getresult(userid);             return responce;         }     }      [servicecontract]     public interface iserviceb     {         string getresult(int64 userid,string str1,string str2,string str3);     }      public class serviceb     {         public string getresult(int64 userid,string str1,string str2,string str3)         {             throw new notimplementedexception();         }     }     ------------------------     service b:     [servicecontract]     public interface iserviceb     {         [webinvoke(method = "post", responseformat = webmessageformat.json, requestformat = webmessageformat.json, bodystyle = webmessagebodystyle.wrapped, uritemplate = "getresult")]         [operationcontract]         string getresult(int64 userid,string str1,string str2,string str3);     }     public class serviceb : basefacedservice, iserviceb     {         public string getresult(int64 userid,string str1,string str2,string str3)         {             //some of code             return responce;         }     }       service webconfig:       <system.servicemodel>         <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" />         <services>           <service name="hi.hello.service.userprofilefacedservice">             <endpoint address="" behaviorconfiguration="restbehav" binding="webhttpbinding" bindingconfiguration="webhttpbindingwithjsonp" contract="hi.hello.service.iserviceb">               <identity>                 <dns value="localhost" />               </identity>             </endpoint>             <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange" />             <host>               <baseaddresses>                 <add baseaddress="http://localhost:8733/design_time_addresses/hi.hello.service./facade1/" />               </baseaddresses>             </host>           </service>           <service name="hi.hello.service.gridconfigfacedservice">             <endpoint address="" behaviorconfiguration="hi.hello.service.gridconfigfacedserviceaspnetajaxbehavior" binding="webhttpbinding" contract="hi.hello.service.gridconfigfacedservice" />           </service>         </services>         <client>           <endpoint address="my client address" binding="webhttpbinding" bindingconfiguration="webhttpbinding_servicereference1" behaviorconfiguration="webhttp" contract="hi.hello.service.serviceb" name="webhttpbinding_servicereference2" />         </client>         <behaviors>           <endpointbehaviors>             <behavior name="restbehav">               <webhttp helpenabled="true" />               <datacontractserializer maxitemsinobjectgraph="2147483647" />             </behavior>             <behavior name="hi.hello.service.gridconfigfacedserviceaspnetajaxbehavior">               <enablewebscript />             </behavior>             <behavior name="webhttp">               <webhttp />             </behavior>           </endpointbehaviors>           <servicebehaviors>             <behavior name="">               <servicemetadata httpgetenabled="true" httpsgetenabled="true" />               <servicedebug includeexceptiondetailinfaults="false" />             </behavior>           </servicebehaviors>         </behaviors>         <bindings>           <nettcpbinding>             <binding name="nettcpbinding_servicereference1" />           </nettcpbinding>           <webhttpbinding>             <binding name="webhttpbindingwithjsonp" crossdomainscriptaccessenabled="true" maxreceivedmessagesize="2147483647" />             <binding name="webhttpbinding_servicereference1" />           </webhttpbinding>          </bindings>       </system.servicemodel>    service b webconfig    <system.servicemodel>     <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" />     <services>       <service name="hi.hello.registry.serviceb">         <host>           <baseaddresses>             <add baseaddress="http://localhost:8733/design_time_addresses/hi.hello.service/facade/"/>           </baseaddresses>         </host>         <endpoint address="" binding="webhttpbinding" contract="hi.hello.registry.iserviceb" behaviorconfiguration="restbehav" bindingconfiguration="webhttpbindingwithjsonp">            <identity>             <dns value="localhost"/>           </identity>          </endpoint>         <!--<endpoint address="" binding="nettcpbinding" contract="hi.hello.registry.iserviceb" bindingconfiguration="nettcpbinding_name">           <identity>             <dns value="localhost"/>           </identity>         </endpoint>-->         <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange"/>       </service>     </services>     <behaviors>       <servicebehaviors>         <behavior>                   </behavior>       </servicebehaviors>       <endpointbehaviors>          <behavior name="restbehav">           <webhttp helpenabled="true"/>           <datacontractserializer maxitemsinobjectgraph="2147483647"/>         </behavior>        </endpointbehaviors>     </behaviors>     <bindings>       <webhttpbinding>         <binding name="webhttpbindingwithjsonp" crossdomainscriptaccessenabled="true"/>       </webhttpbinding>     </bindings>   </system.servicemodel> 

fundamentally, call web service same way, whether written in .net wcf, webapi or other way, or if web service written without .net. must make http request uri.

this not vary depending on calling from. web services called http(s) requests, that's makes them web services.

there several simple mechanisms making web requests .net, including,

system.net.webclient

and newer

system.net.http.httpclient

or, can try , use wcf client approach expanded here, suggest outdated. web service world went restful, both wcf , simpler , more productive webapi.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -