创建一个使用另一个 SOAP 服务 C# 的 REST 服务



我已经做了一个简单的REST服务(WCF(,它将使用另一个SOAP服务。

我的REST服务工作正常,但是当我添加SOAP服务(作为服务引用添加(时,它会将数据添加到Web.config文件中。

我想强调的一件事是,我不想公开SOAP服务,我只是使用它。

但是当我尝试调用操作时,出现此错误:

www.myaddress.com处的终结点没有与 无消息版本。'System.ServiceModel.Description.WebHttpBehavior' 仅用于 WebHttpBinding 或类似绑定。

在互联网上,人们对配置文件有问题,但他们公开了两个服务。我只是公开一项服务,并使用另一项服务。目前,我通过本地主机使用的REST服务,而SOAP服务使用SAML ADFS 身份验证

这就是我的配置文件的样子,有人可以提出修复建议吗?

<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<bindings>
<ws2007FederationHttpBinding>
<binding name="WS2007FederationHttpBinding_mySOAPService">
<security mode="TransportWithMessageCredential">
<message>
<issuer address="issuer.address"/>
<issuerMetadata address="issuer.metadata.address" />
<tokenRequestParameters>
.
.
.
</tokenRequestParameters>
</message>
</security>
</binding>
</ws2007FederationHttpBinding>
<ws2007HttpBinding>
<binding name="binding.address">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" establishSecurityContext="false" />
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<client>
<endpoint address="endpoint.address"
binding="ws2007FederationHttpBinding" bindingConfiguration="WS2007FederationHttpBinding_mySOAPService"
contract="ServiceReference1.mySOAPService" name="WS2007FederationHttpBinding_mySOAPService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>

是的,这正是它默认的工作方式!

但是您可以非常轻松地覆盖这些设置。

var soapService = new SoapClass.SoapService(
new BasicHttpBinding(BasicHttpSecurityMode.Transport), //Pick the right mode here
new EndpointAddress(mySoapUrl));

我的假设是你有多个项目,并且 Soap 被添加到错误的配置中。

另一种选择是将正确的配置设置移动到正确的配置。

最新更新