На самом деле у меня есть две службы, вроде Service A и Service B. Я пытаюсь позвонить в службу A в службу B (как вы сказали, я получил прокси-классы и вызовы). Теперь проблема заключается в том, что когда я обращаюсь к своему сервису А из «почтового клиента для клиента» или «Мобильный», он не работает. На самом деле от клиента («клиентское клиентское приложение для клиента postman» или «Мобильный телефон») Служба A работает нормально, но служба A не может вызвать услугу B. (Удаленный сервер возвратил неожиданный ответ: (400) «Плохой запрос»). Но если я попытаюсь получить доступ к службе A, использующей dll в консольном приложении и вызвав службу A. В это время служба A может называть службу B работоспособной.Как получить доступ к одной службе WCF от другой?
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 my code
return Responce;
}
}
Service A 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>
Как вы называете веб-службы WCF от клиента? Сделайте это так же, потому что в этом случае одна служба WCF является клиентом ... –
Извините, что это невозможно, потому что наши приложения - это приложение на основе службы. :-( –
Я не понимаю этого ответа. Способ доступа к службе WCF почти всегда одинаковый. Обычно вы добавляете ссылку на службу в свой проект и получаете классы прокси для взаимодействия с сервисом. Для служб REST WCF вам необходимо создайте соответствующие «HttpWebRequests». Все, что совершенно не зависит от вопроса, является ли приложение, которое обращается к службе WCF, другой службой или клиентским приложением. –