It Is possible to test a WCF service from browser like in ASMX
I did it in September CTP, but failed in November CTP.
When I use svcutil.exe to generate a proxy, it throws a exception:
D:\>svcutil http://172.21.25.14:8877/MathServices wsdl
Microsoft (R) Service Model Metadata Tool
[Microsoft .NET Framework, Version 2.0.50727.129]
Microsoft Corporation. All rights reserved.
Error: Unable to obtain Metadata from the Uri provided
Error: WS-MetadataExchange Failed on URI:http://172.21.25.14:8877/MathServices
wsdl
The message contains an invalid or expired security context token.
Error: HTTP Get failed on URI:http://172.21.25.14:8877/MathServices wsdl
There was an error downloading 'http://172.21.25.14:8877/MathServices wsdl'.
The request failed with the error message:
--
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://sc
hemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1
">http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</a:Action><a:To s:mustU
nderstand="1">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a
:To></s:Header><s:Body><s:Fault><s:Code><s:Value>s:Sender</s:Value><s:Subcode><s
:Value xmlns:a="a:BadContextTokenhttp://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:V
alue></s:Subcode></s:Code><s:Reason><s:Text xml:lang="zh-CN">The message contain
s an invalid or expired security context token.</s:Text></s:Reason></s:Fault></s
:Body></s:Envelope>
--.
If you would like more help, please type "svcutil / "
D:\>
Any help will be greatly appreciated!
Andy Law

How could I test a WCF service from browser
Reed14676
I had saw the static help page like ASMX in September CTP.
But, are you sure can see the page in November CTP
And, if I have a web browser application(WBA) that using XAML, how could it
communicate with server via WCF service
I heared about that the WBA can only communicate with server by calling Web
Service, and the WCF service can publish as a web service by using
basicHttpBinding/wsHttpBinding. But, how could I connect them
Hope you can give me some advice.
Best regards,
Andy Law
isjam
You can always browse to your WCF service using IE. This should bring up a static help page, similar to the one that you would see for ASMX. From this page you can see the WSDL for the service, and get instructions on how to consume the service using svcutil. Unfortunately, we don't currently support testing the service from the help page at this time. You need to generate a proxy to test the service.
I will look into why you are seeing the error you describe.
Daniel Roth
S0nny88
Thank you very much.
Whit your help, I solve the problem.
The following code only can test it in browsers on September CTP:
Program.cs
namespace MyWsHttpApp
{
class Program
{
static void Main(string[] args)
{
ServiceHost mathHost = new ServiceHost(typeof(MathServices));
try
{
mathHost.Open();
Console.WriteLine("Listening...");
Console.ReadLine();
}
finally
{
mathHost.Close();
}
}
}
[ServiceContract(Name = "MathServices")]
public interface IMathServices
{
[OperationContract]
int Add(int a, int b);
}
public class MathServices : IMathServices
{
#region IMathServices Members
public int Add(int a, int b)
{
return a + b;
}
#endregion
}
}
app.config
< xml version="1.0" encoding="utf-8" >
<configuration>
<system.serviceModel>
<services>
<service type="MyWsHttpApp.MathServices">
<endpoint address="http://172.21.25.14:8877/MathServices"
binding="basicHttpBinding"
contract="MyWsHttpApp.IMathServices" />
</service>
</services>
</system.serviceModel>
</configuration>
The following code can test it in browser on November CTP:
Program.cs
namespace MyWsHttpApp
{
class Program
{
static void Main(string[] args)
{
// Get base address from app settings in configuration
Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);
using (ServiceHost mathHost = new ServiceHost(typeof(MathServices), baseAddress))
{
try
{
mathHost.Open();
Console.WriteLine("Listening...");
Console.ReadLine();
}
finally
{
mathHost.Close();
}
}
}
}
[ServiceContract(Name = "MathServices")]
public interface IMathServices
{
[OperationContract]
int Add(int a, int b);
}
public class MathServices : IMathServices
{
#region IMathServices Members
public int Add(int a, int b)
{
return a + b;
}
#endregion
" />}
}
app.config
< xml version="1.0" encoding="utf-8" >
<configuration>
<appSettings>
<!-- use appSetting to configure base address provided by host -->
<add key="baseAddress" value="http://localhost:8877/MathServices
</appSettings>
<system.serviceModel>
<services>
<service type="MyWsHttpApp.MathServices">
<endpoint address=""
binding="wsHttpBinding"
contract="MyWsHttpApp.IMathServices" />
</service>
</services>
</system.serviceModel>
</configuration>
Thank Daniel and Mike for your help :-)
C Davis
With respect to the WBA, you should expose your WCF service using the BasicHttpBinding. You should then use the Add Web Reference functionality in Visual Studio to generate an ASMX-based proxy for communicating with that service.
Hope that Helps,
-mike
Mike Vernal
Program Manager, WCF