WCF weHttpBinding - 指定要序列化的多个请求正文参数,而不包含任何包装元素

时间:2017-05-05 20:49:40

标签: asp.net wcf iis-7.5

我已经在论坛上搜索了一段时间并尝试了一些不同的东西,但我仍然无法调用从IIS5运行WCF。

我设置了passthrough auth。 Authentication IIS 7.5 settings

这是ASP.NET应用程序weconfig:

<system.web>
    <sessionState timeout="2000"></sessionState>
    <compilation strict="false" explicit="true" targetFramework="4.0" />
    <authentication mode="Windows" />
    <authorization>
      <allow users="d_torreggiani" />
      <deny users="*, ?" />
      <!-- explicitly deny all others, including anonymous -->
    </authorization>
    <!-- 
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
    </authentication>
    -->
    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
    <customErrors mode="Off" />
  </system.web>

  <system.webServer>   
     <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <!--
    <behaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    -->

    <bindings>     
      <!--
      <wsHttpBinding>        
        <binding name="wsHttpBinding_ISER_ProjectStructure" sendTimeout="00:25:00">           
          <security mode="Transport">
            <transport clientCredentialType="Windows"/>
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>

      <basicHttpBinding>
        <binding name="BasicHttpBinding_ISER_ProjectStructure" sendTimeout="00:25:00">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows"/>
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding> 
      -->
      <webHttpBinding >
        <binding name="WebHttpBinding_ISER_ProjectStructure" sendTimeout="00:25:00" >
          <security mode="TransportCredentialOnly" >
            <transport clientCredentialType="Windows"  proxyCredentialType="None" realm="" />

            <!--<message clientCredentialType="UserName" algorithmSuite="Default" />-->
          </security>
        </binding>
      </webHttpBinding>  
    </bindings>    
    <client>
      <endpoint address="http://localhost:8085/SER_ProjectStructure.svc" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_ISER_ProjectStructure" contract="SER_ProjectStructureRef.ISER_ProjectStructure" name="WebHttpBinding_ISER_ProjectStructure" behaviorConfiguration="webHttp"/>      

    </client>    
  </system.serviceModel>
</configuration>

这是WCF服务web.config:

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

  <system.web>
    <compilation strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

这是合同声明

<ServiceContract()>
Public Interface ISER_ProjectStructure

    <OperationContract()> _
    <WebInvoke(BodyStyle:=WebMessageBodyStyle.WrappedRequest, Method:="POST", ResponseFormat:=WebMessageFormat.Json)> _
    Function RunProcedure(ByVal pPath As String, ByVal pProjectName As String) As Result

End Interface

在我的开发机器上它工作正常,但是当我发布它时,我一直收到这个错误:

  

Operation&#39; RunProcedure&#39;合同&#39; ISER_ProjectStructure&#39;指定   多个请求体参数在没有任何包装器的情况下被序列化   元素。最多一个body参数可以在没有包装器的情况下进行序列化   元素。删除额外的身体参数或设置BodyStyle   WebGetAttribute / WebInvokeAttribute上的属性为Wrapped。

有了这个堆栈:

[InvalidOperationException: Operation 'RunProcedure' of contract 'ISER_ProjectStructure' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.]
   System.ServiceModel.Description.WebHttpBehavior.TryGetNonMessageParameterType(MessageDescription message, OperationDescription declaringOperation, Boolean isRequest, Type& type) +972660
   System.ServiceModel.Description.WebHttpBehavior.ValidateBodyStyle(OperationDescription operation, Boolean request) +209
   System.ServiceModel.Description.<>c__DisplayClassa.<GetRequestClientFormatter>b__4() +83
   System.ServiceModel.Description.<>c__DisplayClass7.<GetRequestClientFormatter>b__3() +244
   System.ServiceModel.Description.WebHttpBehavior.GetRequestClientFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) +435
   System.ServiceModel.Description.WebHttpBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) +321
   System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime) +259
   System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters) +432
   System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose) +102
   System.ServiceModel.ChannelFactory.CreateFactory() +46
   System.ServiceModel.ChannelFactory.OnOpening() +86
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +570
   System.ServiceModel.ChannelFactory.EnsureOpened() +117
   System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via) +477
   System.ServiceModel.ClientBase`1.CreateChannel() +58
   System.ServiceModel.ClientBase`1.CreateChannelInternal() +48
   System.ServiceModel.ClientBase`1.get_Channel() +464
   WebInterfaceProjectStructureRoot._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\d_torreggiani\Documents\Visual Studio 2010\Projects\USProjectStructure\WebApplication1\Default.aspx.vb:18
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804

它是什么,我不明白。

提前感谢任何提示。

1 个答案:

答案 0 :(得分:0)

AFAIK如果你正在使用'wrappedrequest&#39;你应该只有一个包含输入属性的实体。

所以你应该创建一个具有输入属性的DTO类,然后你应该在wcf方法中传递这个类的实例。