【问题标题】:Can't Hit a WCF webservice which is being published by Visual Studio无法访问由 Visual Studio 发布的 WCF Web 服务
【发布时间】:2012-05-21 18:24:58
【问题描述】:

更新:我不知道这是否有助于任何人诊断此问题,但 wsdl 的终点为:

http://localhost:8523/Temp/WebService.svc/WebService.svc

这是错误的,我尝试手动更改端点以删除末尾的多余位,但它仍然返回 404

/更新

我正在使用 WCF 开发 Web 服务,当我运行 VS2010 调试器时,我收到以下错误消息:

目标程序集不包含服务类型。您可能需要调整此程序集的代码访问安全策略。

我在网上找到的解决方案说我应该将[ServiceContract]添加到界面中,但它已经存在了。

我还看到有人说我必须从 csproj 文件中删除标记,但这样做会使项目成为类库而不是 Web 服务。

但是我的浏览器会打开一个目录列表,我可以通过单击 .svc 文件然后单击指向 .svc?wsdl 的链接导航到容器生成的 wsdl

如果我尝试从应用程序或 WCF 服务测试器访问服务,我得到一个 404 异常,我将一个测试应用程序拼凑在一起,这是它给我的异常:

Sending Message: Make Call: InteractionId [rt], Destination [ert], ExternalReferenceId [ert], userIdentifier [ert] attachedData [rt]
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://localhost:8523/WebService.svc?wsdl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(TimeSpan timeout)
   at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
   at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Sabio.Avaya.AACC.ProxyServiceLibary.IProxyService.MakeCall(MakeCallRequestData MakeCallRequestData)
   at Sabio.Avaya.AACC.ProxyServiceLibary.WSPipeProxyClient.MakeCall(MakeCallRequestData MakeCallRequestData) in C:\Users\me\Documents\Visual Studio 2010\Projects\WebService\RemoteClientLib\WSPipeProxyClient.cs:line 42
   at ClientLibTestUI.WcfTestApp.MPCWSButton_Click(Object sender, EventArgs e) in C:\Users\me\Documents\Visual Studio 2010\Projects\WebService\ClientLibTestUI\Form1.cs:line 97

这是我的 Web.config:

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WebService" behaviorConfiguration="WebServiceBehaviour">
        <endpoint address="WebService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="DefaultWSBinding"
                  name="WSEndPoint"
                  contract="IWebService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"
                  bindingConfiguration="mexHttpBinding"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/Temp/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="DefaultNetTcpBindingConfig"
                 maxConnections="5"
                 portSharingEnabled="true" >
          <security mode="None"/>
        </binding>

      </netTcpBinding>
      <wsHttpBinding>
        <binding name="DefaultWSBinding">
          <security mode="None"/>
        </binding>
      </wsHttpBinding>

      <mexHttpBinding>
        <binding name="mexHttpBinding"/>
      </mexHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServerServiceBehaviour">
          <!-- 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="true"/>
        </behavior>
        <behavior name="MexBehaviour">
          <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>

        </behavior>
        <behavior name="WebServiceBehaviour">
          <!-- 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>

谁能告诉我我可能做错了什么?如果我在 IIS 或 VS2010 中的内置网络服务器中托管,我会遇到类似的问题

【问题讨论】:

    标签: .net wcf exception iis


    【解决方案1】:

    您的配置中的服务标签错误。应该是这样的:

    <service name="namespace.WebService" behaviorConfiguration="WebServiceBehaviour">
            <endpoint address="WebService.svc"
                      binding="wsHttpBinding"
                      bindingConfiguration="DefaultWSBinding"
                      name="WSEndPoint"
                      contract="namespace.IWebService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange"
                      bindingConfiguration="mexHttpBinding"/>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost/Temp/"/>
              </baseAddresses>
            </host>
          </service>
    

    service 元素中的 name 值和 endpoint 元素中的 contract 值应该是完全限定的。

    【讨论】:

    • 这是我清理我的 Web.config 以删除对客户端的引用的结果,服务名称和端点合同都有命名空间。对不起。
    • 您是否在 IIS 上托管?您的项目中是否有 .svc 文件。您的意思是配置中的服务名称和端点合同被指定为完全限定名称
    • 我尝试在 IIS 和 Cassini (Visual Studio) 中托管我有一个实现 [ServiceContract] 的 .svc 文件我将尝试在一个干净的解决方案中重新加载代码,看看是否行得通...
    • 你能浏览到服务页面并在IE中查看wsdl吗?还可以尝试使用 Fiddler 调用 Web 服务并监控请求响应,看看情况如何?
    • 我可以使用 Service_Name.svc?wsdl 浏览到 wsdl,并将其加载到 SOAP UI 中,该 UI 将为服务生成存根,但当我尝试执行任何方法时它只是 404。
    猜你喜欢
    • 1970-01-01
    • 2013-10-25
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    相关资源
    最近更新 更多