【问题标题】:Make a REST service that uses another SOAP service C#创建一个使用另一个 SOAP 服务 C# 的 REST 服务
【发布时间】:2020-02-07 03:24:52
【问题描述】:

我创建了一个简单的 REST 服务 (WCF),它将使用另一个 SOAP 服务。

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

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

但是当我尝试调用一个操作时,我得到了这个错误:

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

在互联网上,人们对配置文件有疑问,但他们暴露了两个服务。我只是公开一项服务,并使用另一项服务。目前,我通过 localhost 使用的 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>

【问题讨论】:

    标签: c# asp.net rest web-services soap


    【解决方案1】:

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

    但是您可以很容易地覆盖这些设置。

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

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

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

    【讨论】:

    • 感谢您的回复 Austin,但不,我将它们都放在同一个项目中。在那个项目中,我需要在公开 REST 服务时使用 SOAP 服务。
    • 我给出的代码用于连接(使用)一个 SOAP 服务。你能用我给的方法连接/实例化soap服务吗?
    • 是的,它有效。但是当我执行soapService.operation() 时,我得到了那个异常。我创建了一个单独的项目,可以毫无问题地使用那里的 SOAP Web 服务。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多