WCF REST WebInvoke POST返回错误响应

时间:2014-02-03 05:04:59

标签: vb.net wcf

任何人都可以帮助我我已经厌倦了做所有的事情,但是如果字符串长度超过10000个字符,服务会返回错误的返回。

感谢。

这是我的.svc文件:

<%@ ServiceHost Language="VB" Debug="true" Service="BPMMobile" 
    CodeBehind="~/App_Code/BPMMobile.svc.vb"  Factory="MyServiceHostFactory" %>

我的合同:

<OperationContract()> _
   <WebInvoke(UriTemplate:="/SaveData?
Data={Data}", BodyStyle:=WebMessageBodyStyle.Bare, Method:="POST", ResponseFormat:=WebMessageFormat.Xml)> _
    Function SaveData(Data As String) As String

这是我的web.config文件:

<system.serviceModel>
   <bindings>
      <webHttpBinding>
        <binding name="MobileBinding" maxReceivedMessageSize="5242880">
          <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"  />
        </binding>
      </webHttpBinding>
   </bindings>

   <services>
      <service name="BPMMobile">
        <endpoint 
            behaviorConfiguration="webHttp" 
            binding="webHttpBinding" 
            bindingConfiguration="MobileBinding" 
            contract="IBPMMobile" />
      </service>
      <service name="DMSService">
        <endpoint 
            behaviorConfiguration="webHttp" 
            binding="webHttpBinding" 
            contract="IDMSService" />
    </service>
    <service name="ImportMaster">
        <endpoint 
            behaviorConfiguration="webHttp"
            binding="webHttpBinding" 
            contract="IImportMaster"  />
    </service>
   </services>
   <behaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
   </behaviors>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>`

以下是我的自定义服务主机

Public Class MyServiceHost
Inherits WebServiceHost
Public Sub New()
End Sub

Public Sub New(singletonInstance As Object, ParamArray baseAddresses As Uri())
    MyBase.New(singletonInstance, baseAddresses)
End Sub

Public Sub New(serviceType As Type, ParamArray baseAddresses As Uri())
    MyBase.New(serviceType, baseAddresses)
End Sub


Protected Overrides Sub OnOpening()
    MyBase.OnOpening()

    If MyBase.Description IsNot Nothing Then
        For Each endpoint In MyBase.Description.Endpoints
            Dim transport = endpoint.Binding.CreateBindingElements().Find(Of TransportBindingElement)()
            If transport IsNot Nothing Then
                transport.MaxReceivedMessageSize = 5242880
                transport.MaxBufferPoolSize = 5242880
                transport.MaxBufferPoolSize = 5242880
            End If
        Next
    End If
End Sub

结束班

Class MyWebServiceHostFactory
Inherits WebServiceHostFactory
Protected Overrides Function CreateServiceHost(serviceType As Type, baseAddresses As Uri()) As ServiceHost
    Return New MyServiceHost(serviceType, baseAddresses)
End Function

结束班

Public NotInheritable Class MyServiceHostFactory
Inherits System.ServiceModel.Activation.ServiceHostFactory
Public Overrides Function CreateServiceHost(constructorString As String, baseAddresses As Uri()) As System.ServiceModel.ServiceHostBase
    Return MyBase.CreateServiceHost(constructorString, baseAddresses)
End Function

Protected Overrides Function CreateServiceHost(serviceType As Type, baseAddresses As Uri()) As System.ServiceModel.ServiceHost
    Return New MyServiceHost(serviceType, baseAddresses)
End Function

结束班

0 个答案:

没有答案