2

I don't know how configure wcf for accept soap 1.2 request. This is my 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>

When I send request. I got an error(500 - internal server error) or error(400 - bad request).I used some code from this page for request.

/// <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;
        }

I try find some solution. I read this blogs:

Henrik Stenbæk
  • 3,982
  • 5
  • 31
  • 33
user3512982
  • 61
  • 1
  • 9

0 Answers0