将简单的 WCF 服务部署到 Web 服务器

发布于 2024-10-07 07:49:11 字数 1375 浏览 0 评论 0原文

在 IIS 7.0 中创建了一个新目录 XYZ。将 web.config、Service.cs 和 Service.svc 复制到该目录。现在浏览 http://www.mydomain.com/XYZ/Service.svc 我我收到“500 内部服务器错误”。

这是 web.cofig 文件。

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

  <system.web>
    <compilation debug="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>

我认为配置文件可能存在一些问题,但该服务在本地计算机上运行得很好。

Created a new Directory XYZ in IIS 7.0. Copied the web.config, Service.cs and Service.svc to the directory. Now on browsing http://www.mydomain.com/XYZ/Service.svc I am getting a '500 internal server error'.

Here is the web.cofig file.

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

  <system.web>
    <compilation debug="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>

I am thinking there might be some problem with the config file, but the service runs pretty ok on local machine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦欢 2024-10-14 07:49:11

首先,您必须使用 dll 文件而不是代码文件。编译代码并将dll放入“bin”文件夹中。

其次,您没有将端点添加到 web.cofnig 中:

<system.serviceModel>
<!-- ... -->
     <services>
        <service name="SiteService">
            <endpoint address="" binding="basicHttpBinding" 
                 contract="Name of the service interface with namespace, for exanple WebApplication1.IService1" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>      
</system.serviceModel>

并检查 svc 文件,其中的服务名称应与配置文件中的服务名称相对应。如果服务有一行 ,则 svc 文件应为

<%@ ServiceHost Language="C#" Debug="true" Service="SiteService" CodeBehind="Service.cs" %>

At first, you must use dll-file instead of code file. Compile code and put dll into the "bin" folder.

At second, you didn't add endpoints into web.cofnig:

<system.serviceModel>
<!-- ... -->
     <services>
        <service name="SiteService">
            <endpoint address="" binding="basicHttpBinding" 
                 contract="Name of the service interface with namespace, for exanple WebApplication1.IService1" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>      
</system.serviceModel>

And check svc file, a service name inside it should correspond to a service name inside a config file. If a service has a line <service name="SiteService">, svc file should be

<%@ ServiceHost Language="C#" Debug="true" Service="SiteService" CodeBehind="Service.cs" %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文