部署WCF服务,C#,WCF,VS2008

时间:2021-05-23 20:58:13

I have a test project, WCF Service Library, and I published the project. Have a 2003 server with all the right installation. I browse to my application and upon clicking on .svc I get this error.

我有一个测试项目,WCF服务库,我发布了该项目。拥有一台安装正确的2003服务器。我浏览到我的应用程序,点击.svc后出现此错误。

The type 'SearchService', provided as the Service attribute value in the ServiceHost directive could not be found.

无法找到作为ServiceHost指令中的Service属性值提供的类型“SearchService”。

This is the snippet from my web.config

这是我的web.config的片段

<endpoint address="" binding="wsHttpBinding" contract="TestService.ISearchService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>

My Interface:

  [ServiceContract]
public interface ISearchService
{
    [OperationContract]
    string GetName();
}

My Implementation:

   [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class SearchService :ISearchService
{
    #region ISearchService Members

    public string GetName()
    {
      returnn "HAL-2001" 
    }

 }

4 个解决方案

#1


Well, the wsHttpBinding requires you to connect to your service using SOAP - a web browser alone won't cut it, so that's why it's not working when you browse to the .svc file. Nothing wrong there, really.

好吧,wsHttpBinding要求您使用SOAP连接到您的服务 - 仅Web浏览器不会削减它,因此当您浏览.svc文件时它不起作用的原因。没错,真的。

You need to create a real full-fledged SOAP client to connect to your service and test it. Alternatively, you could also use the WcfTestClient.exe test client which sits in your VS2008\Common7\IDE folder.

您需要创建一个真正完整的SOAP客户端来连接到您的服务并进行测试。或者,您也可以使用位于VS2008 \ Common7 \ IDE文件夹中的WcfTestClient.exe测试客户端。

Marc

#2


ANo, the error indicates the host could not find the definition for service implementation "SearchService" in your web.config. In you web.config, you need to wrap the <endpoint> tag in a <service> tag. The name attribute of the <service> should be set to the full name of you SearchService class ( including all namespaces). You also need to define a behavior to enable the service to show WSDL in a browser. You may also want to remove the <dns value="localhost" /> when you deploy the service to a server.

此外,该错误表明主机无法在您的web.config中找到服务实现“SearchService”的定义。在web.config中,您需要将 标记包装在 标记中。 的name属性应设置为SearchService类的全名(包括所有名称空间)。您还需要定义一个行为,以使服务能够在浏览器中显示WSDL。将服务部署到服务器时,可能还需要删除

Here is an example snippet, make sure your put the full class name of SearchService in <service> tag, and also make sure the full class name is in your .svc file:

下面是一个示例代码段,请确保在 标记中放入SearchService的完整类名,并确保完整的类名在.svc文件中:

<system.serviceModel>
 <services>
  <service name="SearchService" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="wsHttpBinding" contract="TestService.ISearchService">
    </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>

#3


ANo, you should switch over to the basicHttpBinding and test to make sure everything is working. You're using the WSHttpBinding and by default it has authentication turned on. You're client will need to pass credentials for it to actually get a response, that's why the browser call isn't working.

你应该切换到basicHttpBinding并测试以确保一切正常。您正在使用WSHttpBinding,默认情况下它已启用身份验证。您的客户端需要为其传递凭据以实际获得响应,这就是浏览器调用无效的原因。

#4


What is your client code calling? For this to work it should be calling a proxy class like the following.

你的客户代码叫什么?为此,它应该调用代理类,如下所示。

class SearchServiceProxy : ClientBase<ISearchService>, ISearchService
{
    public string GetName()
    {
        return Channel.GetName();
    }
}

#1


Well, the wsHttpBinding requires you to connect to your service using SOAP - a web browser alone won't cut it, so that's why it's not working when you browse to the .svc file. Nothing wrong there, really.

好吧,wsHttpBinding要求您使用SOAP连接到您的服务 - 仅Web浏览器不会削减它,因此当您浏览.svc文件时它不起作用的原因。没错,真的。

You need to create a real full-fledged SOAP client to connect to your service and test it. Alternatively, you could also use the WcfTestClient.exe test client which sits in your VS2008\Common7\IDE folder.

您需要创建一个真正完整的SOAP客户端来连接到您的服务并进行测试。或者,您也可以使用位于VS2008 \ Common7 \ IDE文件夹中的WcfTestClient.exe测试客户端。

Marc

#2


ANo, the error indicates the host could not find the definition for service implementation "SearchService" in your web.config. In you web.config, you need to wrap the <endpoint> tag in a <service> tag. The name attribute of the <service> should be set to the full name of you SearchService class ( including all namespaces). You also need to define a behavior to enable the service to show WSDL in a browser. You may also want to remove the <dns value="localhost" /> when you deploy the service to a server.

此外,该错误表明主机无法在您的web.config中找到服务实现“SearchService”的定义。在web.config中,您需要将 标记包装在 标记中。 的name属性应设置为SearchService类的全名(包括所有名称空间)。您还需要定义一个行为,以使服务能够在浏览器中显示WSDL。将服务部署到服务器时,可能还需要删除

Here is an example snippet, make sure your put the full class name of SearchService in <service> tag, and also make sure the full class name is in your .svc file:

下面是一个示例代码段,请确保在 标记中放入SearchService的完整类名,并确保完整的类名在.svc文件中:

<system.serviceModel>
 <services>
  <service name="SearchService" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="wsHttpBinding" contract="TestService.ISearchService">
    </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>

#3


ANo, you should switch over to the basicHttpBinding and test to make sure everything is working. You're using the WSHttpBinding and by default it has authentication turned on. You're client will need to pass credentials for it to actually get a response, that's why the browser call isn't working.

你应该切换到basicHttpBinding并测试以确保一切正常。您正在使用WSHttpBinding,默认情况下它已启用身份验证。您的客户端需要为其传递凭据以实际获得响应,这就是浏览器调用无效的原因。

#4


What is your client code calling? For this to work it should be calling a proxy class like the following.

你的客户代码叫什么?为此,它应该调用代理类,如下所示。

class SearchServiceProxy : ClientBase<ISearchService>, ISearchService
{
    public string GetName()
    {
        return Channel.GetName();
    }
}