Search code examples
c#visual-studiowcfsvcutil.exe

Why does WCF service proxy flie contain http://tempuri.org?


I'm learning to make a basic WCF service. The service runs inside a console app. The client is also a console app on the same computer. I'm using netTCP binding.

I used SvcUtil.exe to generate the proxy class file, and while everything works fine and runs as I expect it to, I'm puzzled by the proxy class file section:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="IService1")]
public interface IService1
{

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/myFunction", ReplyAction="http://tempuri.org/IService1/myFunctionResponse")]
    string[] myFunction();

}

What is http://tempuri.org/IService1/myFunction? To a novice like myself, this seems like a web address. I don't understand what this part of the program is doing and why it's necessary. Did svcutil.exe place any info required for my program on the web? I'm lost.


Solution

  • this seems like a web address.

    This is not exactly a web address. It is a namespace. All you need to do about it is make sure it is unique.

    I don't understand what this part of the program is doing and why it's necessary.

    The namespace is required. It forms part of the contract for your service actions.

    Did svcutil.exe place any info required for my program on the web?

    No, nothing about your program is anywhere other than your own code. Your program can run completely offline.

    Background

    Each web service requires a unique namespace in order to distinguish it from other services. The World Wide Web Consortium recommended using a URI for the namespace because the URI is guaranteed to be globally unique and you're likely to have a domain for your web service.

    Microsoft uses tempuri.org as a default value for web services created with Visual Studio. It stands for Temporary Uniform Resource Identifier, and Microsoft owns that domain. It is only meant to provide a placeholder and must be replaced especially for services on the open web.

    In your case since you probably don't have domain for the service, you can use a fake domain, just make sure it is unique. Technically, it can be anything, not necessarily a URI, but it is recommended to be a URI for consistency. Also it only needs to be unique on your network, which is why even the default tempuri.org worked just fine for you, but it's better to try to come up with a fake domain that is globally unique.