IIS 7.0. Using its machine name in WSDL instead of using domain name.

In WSDL IIS 7.0 uses its machine name in URL if the value has not been given. Well it looks like a bug for an entry level programmer or admin of Windows Server.

Two ways to fix this.

1. Bind the website with a proper domain in IIS. This is working for HTTP. If the WCF service is only for HTTP, IIS will smoothly give WSDL with given domain .

 

2. For HTTPS, modifying the applicationHost.config is needed.
It is located in c:\Windows\System32\inetsrv\config .
applicationConfig
We must modify protocol=”https” bindingInformation to “*:443:www.niceurl.com” .

* this information is only for IIS7.0 above and for IIS6.0 there are some vbs to do that.

IIS 6.0 information is found in below..

http://www.jstawski.com/archive/2008/05/01/wcf-wsdl-location-address-with-https.aspx

WCF Extensibility–Using Message Inspectors

Message inspectors are powerful to inspect inside of envelope of SOAP message. Two sides are available, client side and service side. I think that the biggest value is to inspect client side. Service side is easy to consider what is wrong actually. But client level has a different story.

Three steps are needed.

  1. Create a XXXInspector class implements IClientMessageInspector (or IDispatchMessageInspector for service side) interface.
  2. Create a XXXBehavior class implements IEndpointBehavior. Fill up ApplyClientBehavior method with adding inspector to clientRuntime.
  3. Create a XXXExtensionElement extends BehaviorExtensionElement, which is an abstract class
    And there are two ways for registering those classes.

Using .config file. – need to add custom behavior and behaviorExtensions.

In codes – my personal choice. I prefer not to tamper config file usually.

 

And all soap messages will be captured or modified. Smile

Serialize an object as XML string resources

Using an XMLSerializer could be very useful for checking status of a object. StringBuilder and XMLSerializer is used.

public static string GetSerializedXmlString(Object obj) {
            StringBuilder sbuf = new StringBuilder();
            TextWriter tw = new StringWriter(sbuf);
            XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
            xmlSerializer.Serialize(tw, obj);
           
return sbuf.ToString();
}

But the object must inherits ICollection and it should implement Add(…) method. Otherwise, System.InvalidOperationException occurs.

Weird error when add a service reference into ASP.net web site

I found a strange error when I try to add a service reference (WCF service). As a WCF professional I had no idea what the reason is. Completely no idea for it. So I researched it.

 Weird_Error01

Yay! I found that many people saw same error when they try to that. One Microsoft Community Contributor said that it seems like a bug.

The solution is simple.

Comment the WCF endpoint behavior that causes an error.

Weird_Error03

Add Service.

AddServices

Uncomment the WCF endpoint behavior that causes an error.

Weird_Error02

That’s it.

Link : http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/9beac730-8744-45d4-94db-391550d8cd8f

Consuming WCF service asynchronously

Asynchronous calling is a great idea for applications which use UI on windows or web environments. .Net provides simple and graceful way to use that and those are things that programmer must understand I guess.

Weirdly enough, sometimes I cannot remember how to call async methods on WCF client-side. Smile

There are four steps. Simply enough.

  • Create service client for the service.
  • Create a typed ‘XXXCompleted’ event handler with my call back methods.
  • Create the call back method.
  • Make sure that the call back method has two method signature, Object sender and the generic event argument.
  • Start async method

<a sample>

public void Test01_GettingProduct() {
PPCServiceClient serviceClient = new PPCServiceClient();
// create event handler with callback method
  serviceClient.DoProductQueryCompleted += new EventHandler<DoProductQueryCompletedEventArgs> (DoProductQueryCallBack);
  // Now start async query !!
serviceClient.DoProductQueryAsync(auth);
serviceClient.Close();
}

private void DoProductQueryCallBack(Object sender, DoProductQueryCompletedEventArgs args) {
ProductQueryResult pqr = null;
Product[] products = null;
pqr = args.Result;
products = pqr.Products;

}