wcf - 如何在 SharePoint 服务工厂创建的 WCF 服务中删除 tempuri.org

标签 wcf sharepoint

我正在使用服务工厂类在 SharePoint 2010 上公开 WCF 服务,但无法完全删除生成的 WSDL 中的 tempuri.org 命名空间。

这是我的做法:

ISAPI文件夹中的svc文件

<%@ServiceHost
    Language="C#"
    Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    Service="MyService, [...]"   
%>

服务契约(Contract)

using System.ServiceModel;

    namespace MyService
    {
        [ServiceContract(Namespace="http://myname.com")]
        interface IMyService
        {
            [OperationContract]
            string GetSomeDefinition();
        }
    }

服务实现

using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Microsoft.SharePoint.Client.Services;

    namespace MyService
    {
        [ServiceBehavior(Namespace = "http://myname.com")]
        [BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
        class MyService : IMyService
        {
            public string GetSomeDefinition()
            {
                // do some stuff...
                return result;
            }
        }
    }

WSDL

<wsdl:definitions name="MyService" targetNamespace="http://myname.com" [...]>
  <wsdl:import namespace="http://tempuri.org/" location="http://localhost/_vti_bin/myservice.svc/mex?wsdl=wsdl0" /> 
  [...]
</wsdl:definitions>

现在的问题是 WSDL 一分为二。一个具有正确的新命名空间 http://myname.com和一个具有默认命名空间 http://tempuri.org .通常,您可以通过在端点配置上使用 bindingNamespace 属性来摆脱它。但是因为我使用的是服务工厂,所以我不能这样做。尝试在 web.config 中定义服务端点失败并出现以下错误:绑定(bind)实例已关联到监听 http://localhost/ ...

Web.config block

  <system.serviceModel>
    <services>
      <service name="MyService.MyService">
        <endpoint address="http://localhost/_vti_bin/myservice.svc" binding="basicHttpBinding" contract="MyService.IMyService" bindingNamespace="http://myname.com" />
      </service>
    </services>
  </system.serviceModel>

2010-10-07 更新: 我尝试派生 MultipleBaseAddressBasicHttpBindingServiceHostFactory 并在创建 ServiceHost 时添加端点绑定(bind)命名空间。这不会成功,因为端点集合在那个时间点是空的。

最佳答案

一般来说,您需要在三个地方显式设置命名空间以摆脱 tempuri.org 默认值:

  • ServiceContract 属性(在契约(Contract)上)
  • ServiceBehavior 属性(关于实现)
  • 配置文件中相关服务 元素上的 bindingNamespace。

    --larsw

关于wcf - 如何在 SharePoint 服务工厂创建的 WCF 服务中删除 tempuri.org,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3874290/

相关文章:

c# - 带有 Javascript 客户端的 WCF 自托管 WebSocket 服务

.net - WCF 'A Call to SSPI Failed, see inner exception'

c# - 将 SPFile 保存到本地硬盘

css - Sharepoint 2013 将编辑限制为仅文本

vba - 从 SharePoint 使用 Excel VBA 2016 打开 Powerpoint 文件

javascript - 检查 id 标签内的文本并将类添加到另一个标签

c# - SOAP 是简单对象访问协议(protocol)还是面向服务的应用程序平台?

WCF 4 - TransportWithMessageCredential 使用 X.509 证书进行传输和消息安全

c# - ASP.NET/WCF/IIS 中静态变量的作用域是什么?

sharepoint - 如何在 SharePoint 项目更新事件中识别实际文件更新与项目属性更新