简体   繁体   English

WCF SOAP服务无法处理该消息,因为它发送多部分消息并且需要'text / xml; charset = utf-8'

[英]WCF SOAP service cannot process the message because it sends multipart message and expects 'text/xml; charset=utf-8'

I have a problem with WCF Soap 1.1 configuration. 我对WCF Soap 1.1配置有问题。 I have created a WCF service with basicHttpBinding. 我已经使用basicHttpBinding创建了WCF服务。 Bellow the configuration. 波纹管配置。 The service is WCF_SOAP_REST_SERVICE.BiasImpl: 该服务是WCF_SOAP_REST_SERVICE.BiasImpl:

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServBehave" name="WCF_SOAP_REST_SERVICE.Service">
        <endpoint address="soapService" binding="basicHttpBinding" contract="WCF_SOAP_REST_SERVICE.Service" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service behaviorConfiguration="ServBehave" name="WCF_SOAP_REST_SERVICE.BiasImpl">
        <endpoint address="soapService" binding="basicHttpBinding" bindingConfiguration="basicHttp"
          contract="WCF_SOAP_REST_SERVICE.BiasImpl" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
     <bindings>
        <basicHttpBinding>
          <binding name="basicHttp" bypassProxyOnLocal="true" maxBufferSize="2147483647"
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
             useDefaultWebProxy="false" messageEncoding="Mtom" >
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
      maxArrayLength="2147483647" maxBytesPerRead="2147483647"
      maxNameTableCharCount="2147483647" />
          </binding>
        </basicHttpBinding>
     </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServBehave">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="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>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

I am testing the service using SoapUI. 我正在使用SoapUI测试服务。 The problem is, that I can test the service if I send small packages. 问题是,如果我发送小包裹,我可以测试服务。 I can test it and debug it with Visual Studio, but when I try to send bigger packages (for example a normal request might contain about 500kb because it will contain several images inside), the request is sent using multipart packages, and the WCF binging is configured to accept 'text/xml; 我可以使用Visual Studio对其进行测试和调试,但是当我尝试发送更大的包时(例如,正常的请求可能包含大约500kb,因为其中将包含多个图像),该请求使用多部分包发送,并且WCF绑定配置为接受'text / xml; charset=utf-8'. charset = utf-8'。 So I get this error in SoapUI 所以我在SoapUI中收到此错误

Fri Apr 24 08:16:31 EDT 2015:DEBUG:Receiving response: HTTP/1.1 415 Cannot process the message because the content type 'multipart/related; type="text/xml"; start="<rootpart@soapui.org>"; boundary="----=_Part_0_1561749008.1429877791373"' was not the expected type 'text/xml; charset=utf-8'.

This is the service interface as generated by svcutil.exe. 这是svcutil.exe生成的服务接口。 ( The wsdl is predefined, cannot be changed) (wsdl是预定义的,无法更改)

[System.CodeDom.Compiler.GeneratedCode("System.ServiceModel", "4.0.0.0")]
[ServiceContract(Namespace="http://my.custom.url/codification/", ConfigurationName="Codification")]
public interface Codification{


.
.
.

    [OperationContract(Action="CheckQuality"/*, ReplyAction="*"*/)]
    [FaultContract(typeof(my.custom.url.CodificationFaultDetail), Action="CheckQuality", Name="CodificationFault")]
    [XmlSerializerFormat()]
    [ServiceKnownType(typeof(ResponseTemplate))]
    [ServiceKnownType(typeof(RequestTemplate))]
    CheckQualityResponse CheckQuality(CheckQuality request);

.
.
.

}

This is the implementation: 这是实现:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CodificationImpl : Codification
{
    .
    .
    .

    public CheckQualityResponse CheckQuality(CheckQuality request)
    {
        //implementation goes here
    }

    .
    .
    .
}

CheckQuality class: CheckQuality类:

[System.Diagnostics.DebuggerStepThrough()]
[System.CodeDom.Compiler.GeneratedCode("System.ServiceModel", "4.0.0.0")]
[MessageContract(WrapperName="CheckQuality", WrapperNamespace="http://my.custom.url/codification/", IsWrapped=true)]
public partial class CheckQuality
{

    [MessageBodyMember(Namespace="http://my.custom.url/codification/", Order=0)]
    [System.Xml.Serialization.XmlElement(IsNullable=true)]
    public CheckQualityCheckQualityRequest CheckQualityRequest;

    public CheckQuality()
    {
    }

    public CheckQuality(CheckQualityCheckQualityRequest CheckQualityRequest)
    {
        this.CheckQualityRequest = CheckQualityRequest;
    }
}

What do I have to configure in the WCF service binding to accept multipart messages? 我必须在WCF服务绑定中配置什么才能接受多部分消息?

Please find the below WCF service that works from SOAPUI 请找到以下可从SOAPUI使用的WCF服务

Service 服务

[ServiceContract]
    public interface IImageService
    {
        [OperationContract]
        bool CheckQualityOfImage(CheckQuality objCheckQuality);
    }


    [DataContract]
    public class CheckQuality
    {
        [DataMember]
        public MemoryStream ImageData { get; set; }
        [DataMember]
        public string ImageFileName{ get; set; }
    }

Implementation for the interface below: 以下接口的实现:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class ImageService : IImageService
    {
        public bool CheckQualityOfImage(CheckQuality objCheckQuality)
        {
            if (objCheckQuality != null)
            {
                if (objCheckQuality.ImageData.Length > 0 && ! String.IsNullOrEmpty(objCheckQuality.ImageFileName))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;
        }
    }

Web.config on the server 服务器上的Web.config

<system.serviceModel>
    <bindings>
    <basicHttpBinding>
        <binding name="noSecurity" maxReceivedMessageSize="2147483647">
              <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                            maxDepth="64" maxNameTableCharCount="2147483647" />
              <security mode="None"></security>
            </binding>
    </basicHttpBinding>
    </bindings>
    <services>
          <service name="XMLService.ImageService" behaviorConfiguration="default">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="noSecurity" contract="XMLService.IImageService" />
          </service>
    </services>
    <behaviors>
        <behavior name="default">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />      
        </behavior>
    </behaviors>
</system.serviceModel>

Now my request from SOAPUI is as shown in the screenshots attached 现在,我从SOAPUI发出的请求如所附的屏幕快照所示。

成功

没有文件的空请求

Make sure to match the request properties in SOAPUI. 确保匹配SOAPUI中的请求属性。 Some more information on using SOAPUI with attachments can be found here 有关在附件上使用SOAPUI的更多信息,请参见此处。

NOTE: I have made a few assumptions on properties in the CheckQuality class and I have used a 6MB file for upload 注意:我对CheckQuality类中的属性进行了一些假设,并且使用了6MB的文件进行上传

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法处理该消息,因为内容类型“ application / xml”不是预期的类型“ application / soap + xml”; 字符集= utf-8&#39; - Cannot process the message because the content type 'application / xml' was not the expected type 'application / soap + xml; charset = utf-8 ' HTTP 415 无法处理消息,因为内容类型为“application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - HTTP 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理消息,因为内容类型为 &#39;application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' HTTP / 1.1 415无法处理消息,因为内容类型为&#39;application / json; charset = utf-8&#39;不是预期的类型&#39;text / xml; 字符集= UTF-8&#39; - HTTP/1.1 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' wcf +响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8) - wcf + The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8) 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8), WCF SILVERLIGHT WCF问题:内容类型application / soap + xml; charset = utf-8已发送到需要text / xml的服务; - SILVERLIGHT WCF Issue: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; 内容类型 text/xml; 响应消息的 charset=&quot;utf-8&quot; 与绑定的内容类型不匹配 (text/xml; charset=utf-8) - The content type text/xml; charset=“utf-8” of the response message does not match the content type of the binding (text/xml; charset=utf-8) WCF 服务客户端:内容类型text/html; 响应消息的 charset=utf-8 与绑定的内容类型不匹配 - WCF Service Client: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8) - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM