WCF weHttpBinding - 指定要在没有任何包装器元素的情况下序列化的多个请求正文参数

WCF weHttpBinding - specifies multiple request body parameters to be serialized without any wrapper elements

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

我设置了直通身份验证。 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 '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.

使用此堆栈:

[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

这到底是什么,没看懂

提前感谢您的任何提示。

据我所知,如果您使用 'wrappedrequest',您应该只有一个包含输入属性的实体。

因此您应该创建一个具有输入属性的 DTO class,然后您应该在 wcf 方法中传递 class 的这个实例。