1

我有一个使用 web.config 使用 wcf 服务的示例 Web 应用程序

<system.serviceModel>
  <bindings>
  <wsHttpBinding>
    <binding name="TheBindingConfig">
      <security mode="None" >
         <transport clientCredentialType="None" />
    <message establishSecurityContext="false" />    
    </security>
    </binding>
  </wsHttpBinding>
</bindings>   
    <client>
      <endpoint address="http://localhost/myservice/Service.svc"
        binding="wsHttpBinding" bindingConfiguration="TheBindingConfig"
        contract="myservice.IService" name="WSHttpBinding_IService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

wcf服务配置文件如下

<system.serviceModel>
        <services>
            <service name="myservice.Service" behaviorConfiguration="ServiceBehavior">
                <!-- Service Endpoints -->
                <endpoint address="" binding="wsHttpBinding" contract="myservice.IService">
                    <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <!-- 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>
    </system.serviceModel>

注意服务是使用命名空间“ myservice ”创建的

我是错误响应

The message could not be processed. This is most likely because the action 'http://tempuri.org/IService/GetUserDetails' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

和堆栈跟踪为

[FaultException: The message could not be processed. This is most likely because the action 'http://tempuri.org/IService/GetUserDetails' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9439503
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
   sampleuserservice.IService.GetUserDetails(String Username) +0
   sampleuserservice._Default.BindUserDetails() +57
   sampleuserservice._Default.Page_Load(Object sender, EventArgs e) +90
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

注意:服务按预期正常运行

我猜上面的 webconfig 文件之间存在映射问题

等待您的宝贵回复和建议

4

1 回答 1

0

如果服务可以被任何类型的客户端(.net、soapui)使用,那么发布工作的soap请求(headers + body)和非工作的soap请求。您可以使用 fiddler 或 wcf 日志来获取消息。如果服务根本不工作那么我的猜测是这是因为客户端配置为根本不使用安全性(安全模式=“无”)并且服务器没有绑定配置,所以使用默认值和默认值有一些安全性。

于 2013-06-25T14:46:29.183 回答