我该如何揭露使用WCF入门工具包一个SOAP端点?工具包、我该、入门、SOAP

2023-09-06 22:52:40 作者:是狗总该滚走

我是新来的WCF所以请大家多多包涵。

I am new to WCF so please bear with me.

使用WCF REST入门套件的最新版本,我创建了被称为一个Android应用程序的Web服务。 REST风格的端点工作正常,但我想创造一个SOAP端点使.NET客户端就可以使用它,并生成所有必要的类。

Using the latest version of the WCF REST Starter kit, I created a web service that is being called by an Android application. The RESTful endpoint is working fine but I would like to create a SOAP endpoint so that a .NET client will be able to use it and generate all the necessary classes.

我仍在使用默认的配置文件,我什么我需要做的,它有点困惑。

I am still using the default configuration file and I am a little confused about what I need to do to it.

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

</configuration>

我想我需要添加下面的某个地方到配置文件,但我不能确定它属于的地方,或者如果我在正确的道路上。

I think I need to add the following somewhere into the config file but I am unsure where it belongs or if I am on the right path.

<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="Service1"/>
<endpoint name="soap" address="soap" binding="basicHttpBinding" contract="Service1"/>

我只有一个班,这是Service1.cs。我试图做一些改变,但我没有成功。

I only have one class and that is Service1.cs. I have tried to make some changes but I have had no success.

我想知道我要补充和为什么它需要一个解释,将是美好的。

I would like to know what I have to add and an explanation of why it's needed would be wonderful.

- 更新 -

在我插入的服务标签,我遇到麻烦了添加服务引用功能在Visual Studio中工作。我发现'HttpGetEnabled必须是真实的,所以它会发布服务元数据为http。

After I inserted the services tag, I was having trouble getting the 'Add Service Reference' feature to work in visual studio. I found out that 'HttpGetEnabled' needs to be true, so it would publish the service metadata to http.

我说这一点,好像它的工作。

I added this and it seems like its working.

<behaviors>
          <serviceBehaviors>
              <behavior name="Service1Behavior">
                  <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
              </behavior>
          </serviceBehaviors>
      </behaviors>

如果我添加更多的服务,我必须再创建两个端点的服务呢?

If I add more services, do I have to create two more endpoints for that service too?

感谢。

推荐答案

如果您希望公开您的服务额外的端点,你需要添加这些到&LT;服务名称=... &gt;在你的config 标签:

If you want to expose additional endpoints on your service, you need to add those to the <service name="...."> tag in your config:

<system.serviceModel>
  <services>
    <service name="NameSpace.ServiceClassName>
       <endpoint name="rest" 
                 address=""
                 binding="webHttpBinding"
                 contract="IService1" />
       <endpoint name="soap" 
                 address="soap"
                 binding="basicHttpBinding"
                 contract="IService1" />
       <endpoint name="mex" 
                 address="mex"
                 binding="mexHttpBinding"
                 contract="IMetadataExchange" />
    </service>
  </services>
</system.serviceModel>

你显然使用WCF 4标准的端点被暴露 - 如果你想改变这种状况,你需要明确地列明所有的配置,你需要

You're obviously using the WCF 4 standard endpoints being exposed - if you want to change that, you will need to explicitly spell out all your config you need.

现在,您的服务(如 ServiceClassName 实施中的命名空间命名空间)将有三个端点:

Now, your service (as implemented in ServiceClassName in the NameSpace namespace) will have three endpoints:

您* .svc文件的基地址将使用REST端点的WebHttpBinding (service.svc)/ SOAP 地址是相同的合同(同一服务的方法),但使用基于SOAP的 basicHttpBinding的(service.svc)/ MEX 地址将服务元数据的SOAP客户端 the base address of your *.svc file will be the REST endpoint using webHttpBinding the (service.svc)/soap address will be the same contract (same service methods), but using the SOAP-based basicHttpBinding the (service.svc)/mex address will have the service metadata for the SOAP clients
 
精彩推荐
图片推荐