如何承载我的WCF服务在我的网站? [英] How to host my WCF service in my website?

查看:195
本文介绍了如何承载我的WCF服务在我的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的WCF。我已经开发了一个样本WCF服务。我的服务使用 basicHttp 绑定。

I am new to WCF. I have developed a sample WCF service. My service uses the basicHttp binding.

我主持我的服务于本地IIS 7.5使用WAS和它工作正常。现在我想我的托管服务在我的网站。

I host my service in local IIS 7.5 using WAS and it works fine. Now I want to host my service in my website.

我搜索谷歌,但有大部分都是在本地主机托管在IIS。请告诉我如何我做到这一点?这将是更好的操作指南,参考了一些教程或一步。

I search Google but there most of them are hosted in localhost in IIS. Please tell me how to I do that? It will be better to refer some tutorial or step by step guide.

推荐答案

您有两种基本的选择,我相信:

You have basically two options, I believe:

选项1 - bin的部署(preferred选项)

Option 1 - "bin" deploy (preferred option)


  1. 编译WCF服务为一体的DLL(类库)

  2. 在IIS中创建网站

  3. 复制WCF DLL的进入该网站的。\\ BIN 文件夹

  4. 创建一个 *。SVC 文件在该网站

  5. 在网页文件夹中添加适当的的web.config 来定义你的终端和服务配置等。

  1. compile your WCF service into a DLL (class library)
  2. create a website in IIS
  3. copy the WCF DLL's into the website's .\bin folder
  4. create a *.svc file in that website
  5. add an appropriate web.config in the website folder to define your endpoints and service configuration etc.

您WCF服务现在将在该网站的基地址访问,加上 *。SVC 文件,例如名称。

Your WCF service will now be reachable at the website's base address, plus the name of the *.svc file, e.g.

http://myserver/someweb/Myservice.svc

* SVC 会是这个样子:

<%@ ServiceHost Language="C#" Debug="true" 
    Service="WCF_Simple_Service.HelloIndigoService"  %>

=服务属性表示实现服务的类 - 其命名空间完全限定

The Service= attributes denotes the class implementing the service - fully qualified with its namespace.

选项2 - 把东西到 APP_ code

Option 2 - put stuff into App_Code


  1. 在IIS中创建网站

  2. 把你所有相关的WCF * CS 文件直接到 \\ APP_ code 文件夹

  3. 创建一个 *。SVC 文件在该网站

  4. 在网页文件夹中添加适当的的web.config 来定义你的终端和服务配置等。

  1. create a website in IIS
  2. put all your WCF related *.cs files directly into the .\App_Code folder
  3. create a *.svc file in that website
  4. add an appropriate web.config in the website folder to define your endpoints and service configuration etc.

您WCF服务现在将在该网站的基地址访问,加上 *。SVC 文件,例如名称。

Your WCF service will now be reachable at the website's base address, plus the name of the *.svc file, e.g.

http://myserver/someweb/Myservice.svc

* SVC 会是这个样子:

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

有一个简单,样本的web.config 可能是这个样子:

A simple, sample web.config might look something like this:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="WithDebug">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  <services>
    <service name="SimpleWCF.HelloIndigoService" behaviorConfiguration="WithDebug">
      <endpoint
          address=""
          binding="basicHttpBinding"
          contract="SimpleWCF.IHelloIndigoService" />
      <endpoint
          address="mex"
          binding="mexHttpBinding"
          contract="IMetadataExchange" />
    </service>
  </services>
</system.serviceModel>

您基本上是定义你的&LT;服务&GT; 标记 - 和重申:名称= 表示实现类服务 - 其命名空间完全限定。它必须包含至少一个端点 - 一个墨西哥端点是可选的 - 但非常有用的,特别是用于开发和测试。它允许客户发现的服务,并得到其服务的描述,因此它可以与它交互。

You basically define your <service> tag - and again: the name= denotes the class implementing the service - fully qualified with its namespace. It must contain at least one endpoint - a "mex" endpoint is optional - but very useful, especially for development and testing. It allows client to "discover" the service and get its service description so it can interface with it.

一旦你的服务被部署在IIS中,您可以使用像 WCF测试看到它在行动客户的附带免费与WCF,或了SoapUI 这是一个通用的SOAP测试工具(为你免费版使用)。

Once your service is deployed in IIS, you can see it in action using a tool like the WCF Test Client that ships for free with WCF, or SoapUI which is a general-purpose SOAP testing utility (with a free edition for you to use).

这篇关于如何承载我的WCF服务在我的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆