fiddler HTTP / 1.1 415错误,因为内容类型为'multipart / form-data; “ application / xop + xml

问题描述 投票:0回答:1

我有一个WCF https://localhost/SupportingDocsFacade/NextGenService.svc/Upload。我正在尝试使用提琴手作曲家访问服务,并收到以下错误

HTTP / 1.1 415无法处理消息,因为内容类型'多部分/表单数据;boundary = ------------- acebdf13572468'不是预期的输入'multipart / related;类型=“ application / xop + xml”'。

Webservice期望文件附带服务。所以我将一个文件附加到作曲家enter image description here

下面是WCF服务器中的Webconfig

<wsHttpBinding>
        <binding messageEncoding="Mtom" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" name="WsBinding" transactionFlow="false" textEncoding="utf-8"  >
          <security mode ="TransportWithMessageCredential">
            <message clientCredentialType="UserName"></message>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

以下是Web配置中的行为部分

 <behavior name="NextGenServiceBehavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        <serviceCredentials>

            <userNameAuthentication userNamePasswordValidationMode="Custom"
             customUserNamePasswordValidatorType="SupportingDocsFacade.ServiceAuthenticator,SupportingDocsFacade" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>

<service behaviorConfiguration="NextGenServiceBehavior" name="SupportingDocsFacade.NextGenService">
        <endpoint address="/Upload" binding="wsHttpBinding" bindingConfiguration="WsBinding" name="Basic" contract="SupportingDocsFacade.INextGenService" />

      </service>

我也尝试过使用SOAP UI,但没有得到结果。

然后,我尝试使用客户端UI并进行了测试。它还会引发以下错误

发件人-无法处理该消息。这很可能因为动作“ http://tempuri.org/INextGenService/UploadDocNextGen”不正确或因为该消息包含无效或过期的安全上下文令牌或因为绑定之间不匹配。安全如果服务由于中止通道而导致上下文令牌无效不活动。防止服务中止空闲会话过早增加服务端点的接收超时绑定。

下面是客户端appconfig

 <system.serviceModel>
        <client>
            <endpoint address="https://localhost/SupportingDocsFacade/NextGenService.svc/Upload"
                binding="wsHttpBinding" bindingConfiguration="Basic" contract="NextGenService.INextGenService"
                name="Basic" />
        </client>
        <bindings>
            <wsHttpBinding>
                <binding name="Basic" messageEncoding="Mtom">
                    <security mode="Transport">
                        <transport clientCredentialType="None" />
                        <message clientCredentialType="UserName" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>

    </system.serviceModel>
c# wcf authentication mtom
1个回答
0
投票

问题的关键是SOAP Web服务的调用存在问题。调用Wshttpbinding创建的WCF服务的一般方法是使用代理类发送客户端请求。这样,我们要么更改服务的调用方式,要么使用Webhttpbinding创建Rest API。您只能通过上述方式调用休息样式服务。请参考以下创建服务的方式。IService。

   [OperationContract]
        [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,BodyStyle =WebMessageBodyStyle.Bare)]
        Task UploadStream(Stream stream);

Service1.svc

public async Task UploadStream(Stream stream)
{
    var context = WebOperationContext.Current;
    string filename = context.IncomingRequest.Headers["filename"].ToString();
    string ext = Path.GetExtension(filename);
    using (stream)
    {
        //save the image under the Uploads folder on the server-side(root directory).
        using (var file = File.Create(Path.Combine(HostingEnvironment.MapPath("~/Uploads"), Guid.NewGuid().ToString() + ext)))
        {
            await stream.CopyToAsync(file);
        }
    }
}

webconfig。

<system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" name="httpbinding">
          <security mode="None">
          </security>
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147473647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
        </binding>
        <binding name="httpsbinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147473647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
      <!--http and https are all supported.-->
      <add binding="webHttpBinding" scheme="http" bindingConfiguration="httpbinding"/>
      <add binding="webHttpBinding" scheme="https" bindingConfiguration="httpsbinding"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

随时告诉我是否有什么我可以帮助的。

© www.soinside.com 2019 - 2024. All rights reserved.