为接受肥皂1.2配置wcf

时间:2015-09-10 11:51:38

标签: c# web-services wcf soap

我不知道如何为接受soap 1.2请求配置wcf。 这是我的web.config。

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="PortSoapBinding" />
        <binding name="PortHttpBinding" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="" binding="basicHttpBinding"
          bindingConfiguration="PortHttpBinding" contract="IService"
          name="Service" />
    </client>
    <services>
      <service name="WCF.Service">
        <endpoint address="" binding="basicHttpBinding"
          bindingConfiguration="PortSoapBinding" contract="IService"
          name="Service" />
      </service>
    </services>
  </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>

当我发送请求时。我收到错误(500 - 内部服务器错误)或错误(400 - 错误请求)。我使用了此页面中的一些代码来请求。

/// <summary>
        /// Execute a Soap WebService call
        /// </summary>
        public static void Execute3()
        {
            HttpWebRequest request = CreateWebRequest();
            XmlDocument soapEnvelopeXml = new XmlDocument();
            soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""UTF-8""?>

<soapenv:Envelope xmlns:tem=""http://tempuri.org/"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">

<soapenv:Header/>

<soapenv:Body>

<tem:echo/>

</soapenv:Body>

</soapenv:Envelope>");

            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    string soapResult = rd.ReadToEnd();
                    Console.WriteLine(soapResult);
                }
            }
        }
        /// <summary>
        /// Create a soap webrequest to [Url]
        /// </summary>
        /// <returns></returns>
        public static HttpWebRequest CreateWebRequest()
        {

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:64482/Service1.svc");
            webRequest.Headers.Add(@"SOAPAction: http://tempuri.org/IService1/echo");
            webRequest.ContentType = "application/soap+xml; charset=utf-8";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }

我尝试找到一些解决方案。我读了这篇博客:

0 个答案:

没有答案