Where is tempuri.org in the WSDL?
If you browse the service WSDL you will see tempuri.org all over the place. Here is a default WCF service WSDL.
<wsdl:definitions name="Service1" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:63720/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IService1_DoWork_InputMessage">
<wsdl:part name="parameters" element="tns:DoWork"/>
</wsdl:message>
<wsdl:message name="IService1_DoWork_OutputMessage">
<wsdl:part name="parameters" element="tns:DoWorkResponse"/>
</wsdl:message>
<wsdl:portType name="IService1">
<wsdl:operation name="DoWork">
<wsdl:input wsaw:Action="http://tempuri.org/IService1/DoWork" message="tns:IService1_DoWork_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IService1/DoWorkResponse" message="tns:IService1_DoWork_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="DoWork">
<soap:operation soapAction="http://tempuri.org/IService1/DoWork" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1">
<wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1">
<soap:address location="http://localhost:63720/Service1.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Tip: Use a constant to ensure consistency
I like to use a constant to provide a consistent namespace across my services
public class Constants
{
// Ensures consistency in the namespace declarations across services
public const string Namespace = "http://contoso.com/services/";
}
How to eliminate tempuri.org from WCF Services WSDL
Step 1: Declare a namespace on your service contract
The namespace can be anything. People typically use a URI of some form but it does not have to point to an actual web page. Often people will use a version identifier in the namsepace but there are no rules about what you should do.
// Eliminate tempuri.org from the contract
// If you don't want to us a constant, put the URI here
// [ServiceContract(Namespace = "http://contoso.com/services")]
[ServiceContract(Namespace = Constants.Namespace)]
public interface IService1
{
[OperationContract]
void DoWork();
}
Step 2: Declare a namespace on your service
The service namespace is added with a ServiceBehavior attribute. Using the constant ensures that the namespace is the same for the contract and the service.
// If you don't want to us a constant, put the URI here
// [ServiceBehavior(Namespace = "http://contoso.com/services")]
[ServiceBehavior(Namespace = Constants.Namespace)]
public class Service1 : IService1
{
public void DoWork()
{
}
}
Step 3: Set the binding namespace
<system.serviceModel>
<services>
<service name="EliminateTempUri.Service1">
<!-- Use a bindingNamespace to eliminate tempuri.org -->
<endpoint address=""
binding ="basicHttpBinding"
bindingNamespace="http://contoso.com/services"
contract="EliminateTempUri.IService1"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
How to eliminate tempuri.org from Workflow Services WSDL
For workflow services the process is slightly different. Workflow services do not have a contract (it is inferred from the activities) so here is the process.
Step 1: Declare a namespace on each receive activity
I wish it were possible to use a constant here but sadly it is not. For each receive activity you must declare the namespace and contract name using a special syntax of {namespace}IContractName. In this example I’ve set the ServiceContractName property to {http://contoso.com/services}IService
Step 2: Declare a namespace for the Workflow Service
- Open the Workflow Service and click in the designer outside of an activity. This will allow you to set the properties of the service itself.
- Set the Name property to use the same namespace as you see below.
Step 3: Set the binding namespace
Many people do not declare a <service> tag for their Workflow Services but if you want to eliminate tempuri.org you will need to declare it.
For a Workflow Service the A,B,Cs of WCF configuration are a little different.
- Service Name – use the ConfigurationName property from the WorkflowService
- A – Address – should be blank when hosted in IIS / AppFabric
- B – Binding – use the binding of your choice. Typically basicHttpBinding
- C – Contract – use the interface name from the ServiceContractName property (without the namespace)
<!-- For Workflow Services name is the ConfigurationName property -->
<service name="Service2">
<!-- contract must match the receive activity -->
<!-- Use a bindingNamespace to eliminate tempuri.org -->
<endpoint address=""
binding ="basicHttpBinding"
bindingNamespace="http://contoso.com/services"
contract="IService"
/>
</service>
Test It Out
- Right click on your WCF or Workflow Service in Visual Studio and select View In Browser.
- Click on the link to view the WSDL
- Search in the browser for tempuri.org – there should be no matches
Happy Coding!
相关推荐
浏览wcf的wsdl无法显示的问题.docx
标题 "C# 使用 WCF 开发,将 WSDL 文件生成 .h 文件" 涉及的是Windows Communication Foundation(WCF)技术,这是.NET框架中用于创建分布式应用程序的服务模型。WSDL(Web Services Description Language)是一种...
在IT行业中,Web服务是应用程序之间交互的一种标准方式,而WSDL(Web Services Description Language)则是用来定义这些服务接口的XML格式规范。本项目“WSDL.rar”提供了一个C#编写的WSDL解析器,旨在帮助开发者更...
本教程将详细介绍如何在C#中调用WCF服务,以及在Visual Studio环境下创建和测试这个过程。 首先,理解WCF服务的基本概念至关重要。WCF服务是一种面向服务的架构,它允许开发者创建可以在网络上不同系统之间交换数据...
在VB6中访问WCF(Windows Communication Foundation)服务是一项技术挑战,因为VB6不直接支持WCF的现代通信协议。然而,通过使用一些特定的工具和技术,如Soap Toolkit 3.0,我们可以实现这一目标。以下是一些关于...
Web Service,SOAP,XML,WSDL,WCF综合介绍
在Windows Communication Foundation(WCF)框架中,`MessageContract`是一种高级消息模式,它允许开发者对消息的结构有更精细的控制。与传统的数据契约(DataContract)不同,消息契约直接操作SOAP消息的结构,提供...
### WCF中应用泛型 #### 一、泛型概念的理解与重要性 在软件开发领域,特别是面向对象编程中,泛型是一种重要的编程技术,它允许开发者编写一种类型的代码来处理不同的数据类型,从而提高了代码的复用性和灵活性。...
1. **创建WSDL**: 首先,你需要拥有WCF服务的WSDL(Web Service Description Language)文件,它是WCF服务的接口描述,包含了服务的地址、绑定、消息格式等信息。在CSDN博客中提到的链接(由于此处无法直接提供链接...
在WCF中,事务(Transaction)是一个关键概念,它确保一系列操作要么全部成功,要么全部失败,以此来维护数据的一致性。本项目以银行转账为例,展示了如何在WCF服务中实现事务处理。 **银行转账**是一个典型的涉及...
Windows Communication Foundation (WCF) 是微软.NET框架中的一种全面的服务导向架构,用于构建可互操作的分布式应用程序。它整合了多种通信技术,如Web服务、消息队列、Remoting等,为开发者提供了一种统一的方式来...
在标题和描述中提到的“WCFService可以通过web调用和WCF服务访问”,这意味着该服务已经配置为允许两种不同的调用方式。 1. **Web调用**:WCF服务可以通过HTTP协议暴露为Web服务,允许任何支持SOAP协议的客户端进行...
在本文中,我们将深入探讨如何在Windows Communication Foundation(WCF)服务中使用泛型,通过具体的示例来阐述这一技术的应用。WCF是.NET框架中的一个关键组件,用于构建分布式应用程序,而泛型则是一种强大的编程...
在.NET框架中,Windows Communication Foundation(WCF)是一种用于构建分布式应用程序的服务模型,它提供了统一的方式来进行跨进程、跨网络的通信。WCF服务可以被各种类型的客户端访问,包括WinForms应用程序。本...
1. **生成服务代理**: 使用“svcutil.exe”工具,从WCF服务的元数据(WSDL和XSD文件)生成C++客户端代理类。在命令行中输入: ``` svcutil http://serviceurl/mex /t:code /l:C++ /n:*,MyNamespace ``` 这将生成包含...
在.NET框架中,Windows Communication Foundation(WCF)是一种强大的服务导向架构,用于构建分布式应用程序。在常规情况下,WCF服务的配置通常通过`.config`文件进行,这些文件包含服务地址、绑定、行为等信息。...
在.NET框架中,Windows Communication Foundation(WCF)是一种用于构建分布式应用程序的服务模型,它提供了丰富的功能,包括数据交换、安全性和事务处理。本篇将深入探讨WCF中的`DataContract`和`DataMember`这两个...
在.NET框架中,Windows Communication Foundation (WCF) 是一种用于构建分布式应用程序的服务模型。它提供了一种统一的方式来创建、发布和调用服务。在传统的WCF应用中,服务的配置通常通过XML配置文件(如app....
在IT行业中,Web服务是一种常用的数据交换机制,而Windows Communication Foundation(WCF)是微软提供的一个全面、统一的框架,用于构建面向服务的应用程序。WCF服务通常由.NET Framework开发,可以处理各种协议和...
- WSDL获取:WCF服务通常会暴露其WSDL地址,这可以通过查看服务的元数据(如添加服务引用时在.NET中的操作)或者直接从服务URL获取。 2. **配置连接参数**: - 设置URL:在生成的Java客户端代理中,需要设置服务...