gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:41:13 27 4
gpt4 key购买 nike

我正在使用服务工厂类在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com