So I had to upgrade an old web service from a Visual Studio 2008 project to a Visual Studio 2012 project. When I went to do a build on my local machine I kept getting the "Cannot create type xxx" error on my asmx web service.
Ultimately, after playing around and researching, the fix is this. The webservice is looking for the dll files in the bin directory. The problem is if you are debugging the web service on your local machine the dll's will be outputted to either the bin\debug or the bin\release folders. You need to grab those dll's and move them up on to just the bin folder, and at least for me the error went away.
Happy Coding.
A Southwestern adventurer striking out into the badlands of the Midwest for fun, profit, and for a wife who wouldn't move back to the Southwest :)
Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts
Monday, May 11, 2015
Monday, June 09, 2014
WCFExtras No Longer Needed In ASP.Net 4.5+ For Flat WSDLs
So I started a new WCF Service Application Project in Visual Studio 2013. I soon ran into the "Where are all the missing parts of my WSDL?" I then remembered something about needing WCFExtras to generate "flat" WSDLs with all the pieces parts in WCF. In googling around about the difference between WCFExtras and WCFExtrasPlus was I found some good news...
WCF in the .Net framework 4.5+ will generate "flat" WSDLs for you without the need of WCFExtras!
All you need to do is have your connecting clients point themselves to..
http://someurl/someport/someservice.svc?singlewsdl
Just add the ?singwsdl at the end of your service.svc and the full WSDL for your WCF is exposed without any missing pieces parts.
Win.
Here is a [LINK] for more info.
WCF in the .Net framework 4.5+ will generate "flat" WSDLs for you without the need of WCFExtras!
All you need to do is have your connecting clients point themselves to..
http://someurl/someport/someservice.svc?singlewsdl
Just add the ?singwsdl at the end of your service.svc and the full WSDL for your WCF is exposed without any missing pieces parts.
Win.
Here is a [LINK] for more info.
Thursday, January 21, 2010
Another WCF Gotcha
Oh my friend WCF. My latest love affair with WCF occured when connecting to an unsecured asmx web service for testing using WCF. I added a service reference to my web project, the proxy classes created fine, so I connected and...hang!
I ended up using the srvutil to output a config file that had different settings then the auto generated config entries for binding that WCF created when adding the service reference to my project. Using the new config file actually worked, but be careful, because I think WCF will cache server reponses for a minute or two. I know this doesn't make any sense, but it seems like if you change the config settings, fire up your project again, and try to connect, you will error out unless you wait a minute or two. Just a tip.
Anyway, here is a link for dealing with WCF using Srvutil.
http://nayyeri.net/integrating-wcf-clients-with-asmx-services
and a link for WCF bindings
http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.aspx
I ended up using the srvutil to output a config file that had different settings then the auto generated config entries for binding that WCF created when adding the service reference to my project. Using the new config file actually worked, but be careful, because I think WCF will cache server reponses for a minute or two. I know this doesn't make any sense, but it seems like if you change the config settings, fire up your project again, and try to connect, you will error out unless you wait a minute or two. Just a tip.
Anyway, here is a link for dealing with WCF using Srvutil.
http://nayyeri.net/integrating-wcf-clients-with-asmx-services
and a link for WCF bindings
http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.aspx
Sunday, October 05, 2008
Decent WCF/JSON Chat Application
Here is a pretty good JSON/WCF interop example chat application with source code provided.
http://blogs.msdn.com/bashmohandes/archive/2008/01/05/using-webhttpbinding-json-support-in-wcf.aspx
http://blogs.msdn.com/bashmohandes/archive/2008/01/05/using-webhttpbinding-json-support-in-wcf.aspx
Friday, October 03, 2008
Misadventures in WCF
Well, I started off on a simple task of creating a test WCF service hosted in a windows service that was secured by https and was compatible with older clients.
Here were my hurdles. I'll come back and post links to each step.
1) Getting a WCF Service Working
2) Getting a Windows Service Working
3) Getting my WCF service class working in a Windows Service
4) Getting SSL working
5) Getting basicHTTBinding anonymous username/password working
Here is where I started running into trouble
6) Getting XML enums to serialize correctly in WCF.
7) Possibly needing to flatten WSDL files
8) WCF clients can connect to the mex and discover the service, but displaying the description or the WSDL in a web browser returns 400 or 415 errors (could be related to #7).
So, I decided at least for now to say "f it" and drop the project. Instead I will use an ASMX old school service hosted on IIS.
So far the WSDL issues went away, the challenge will be testing SSL (since I don't have IIS running on my box). I will give myself bonus points if I get the ASMX service working with SSL in a Windows Service, but that is a low priority at this point as time is a'wasting. I get super bonus points when if I'm done and have any time left, I can circle back and get the WCF working.
The lesson here? WCF is great...going forward. If any part of your tech lies in the "legacy" realm, <sarcasm>like Java or non MS clients </sarcasim> don't listen to all the folks towting how great WCF is and how it is backwards compatible, go ASMX.
Here were my hurdles. I'll come back and post links to each step.
1) Getting a WCF Service Working
2) Getting a Windows Service Working
3) Getting my WCF service class working in a Windows Service
4) Getting SSL working
5) Getting basicHTTBinding anonymous username/password working
Here is where I started running into trouble
6) Getting XML enums to serialize correctly in WCF.
7) Possibly needing to flatten WSDL files
8) WCF clients can connect to the mex and discover the service, but displaying the description or the WSDL in a web browser returns 400 or 415 errors (could be related to #7).
So, I decided at least for now to say "f it" and drop the project. Instead I will use an ASMX old school service hosted on IIS.
So far the WSDL issues went away, the challenge will be testing SSL (since I don't have IIS running on my box). I will give myself bonus points if I get the ASMX service working with SSL in a Windows Service, but that is a low priority at this point as time is a'wasting. I get super bonus points when if I'm done and have any time left, I can circle back and get the WCF working.
The lesson here? WCF is great...going forward. If any part of your tech lies in the "legacy" realm, <sarcasm>like Java or non MS clients </sarcasim> don't listen to all the folks towting how great WCF is and how it is backwards compatible, go ASMX.
Tuesday, September 09, 2008
WCF Axis Interop Null Problem
I had a small project where I used a WCF web client to connect to an Axis/Coldfusion web service. I could add the service reference and call the web method fine, but the return string (that let me know if the data passed to the web service was processed correctly on the Axis end) always returned null.
I did some logging of the SOAP calls (see previous post) and the service was sending me back the return string, just my automatically generated classes were not reading it for some reason.
So after pooling my hair out for a LONG time, I finally figured out (with the help of a few bloggers) what the issue was.
Well apparently WCF basicHTTPbinding (and possibly other binding types as well) doesn't like rpc style web services. I thought "awww crud" I'm going to have to ask the service company to rewrite their web service, which probably wouldn't go over very well. But then I found this blog.
http://www.vistax64.com/indigo/54127-wcf-client-does-not-read-streamed-response.html
Note in the second post, the poster said he went in and changed the behavior's operational style to use document and literal, and the null problem went away. I did that in my auto generated proxy class (it is hidden by default, you need to click the show all files icon, then it should be named something like References.cs).
I change this-
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
to this -
[System.ServiceModel.XmlSerializerFormatAttribute ( Style = System.ServiceModel.OperationFormatStyle.Document, Use = System.ServiceModel.OperationFormatUse.Literal)]
And wallah! The return string went from null to a value.
Hope this helps someone.
I did some logging of the SOAP calls (see previous post) and the service was sending me back the return string, just my automatically generated classes were not reading it for some reason.
So after pooling my hair out for a LONG time, I finally figured out (with the help of a few bloggers) what the issue was.
Well apparently WCF basicHTTPbinding (and possibly other binding types as well) doesn't like rpc style web services. I thought "awww crud" I'm going to have to ask the service company to rewrite their web service, which probably wouldn't go over very well. But then I found this blog.
http://www.vistax64.com/indigo/54127-wcf-client-does-not-read-streamed-response.html
Note in the second post, the poster said he went in and changed the behavior's operational style to use document and literal, and the null problem went away. I did that in my auto generated proxy class (it is hidden by default, you need to click the show all files icon, then it should be named something like References.cs).
I change this-
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
to this -
[System.ServiceModel.XmlSerializerFormatAttribute ( Style = System.ServiceModel.OperationFormatStyle.Document, Use = System.ServiceModel.OperationFormatUse.Literal)]
And wallah! The return string went from null to a value.
Hope this helps someone.
Monday, September 08, 2008
WCF Soap Logging
I read a few articles about logging your outgoing and incoming SOAP messages. The simpliest way I found to trace SOAP messages is here-
Rick Stahl's Blog - http://www.west-wind.com/weblog/posts/205198.aspx
More Info from MS - http://msdn.microsoft.com/en-us/library/ms730064.aspx
Another useful tool called Web Services Studio Jason from the Arizona .Net User Group pointed me too-
http://code.msdn.microsoft.com/webservicestudio20
- is also very useful for debugging older web services (though it works with a lot of WCF stuff too).
Rick Stahl's Blog - http://www.west-wind.com/weblog/posts/205198.aspx
More Info from MS - http://msdn.microsoft.com/en-us/library/ms730064.aspx
Another useful tool called Web Services Studio Jason from the Arizona .Net User Group pointed me too-
http://code.msdn.microsoft.com/webservicestudio20
- is also very useful for debugging older web services (though it works with a lot of WCF stuff too).
Wednesday, September 03, 2008
WCF SSL Password Negotiation Errors
Ok, I'm using WCF to try to connect to a basic webservice hosted on a coldfustion server. The webservice that I'm connecting to communicates over https and expects a username and password. So, after bumping around and doing some research, I was able to come up with this.
Again, sorry about the code display. If you select and copy/paste the code will be much more readable.
First, in your config file (or in code I guess, my example is a config file), replace whatever was automatically generated for your security setting in your binding when you added the service with the following.
Next, you have to pass the username and password to the webservice. This I did in code, you can probably put the username and password in your config file somewhere as well. Here is a sample page_load method I did for a web page to do a test of the webservice.
Here are the namespaces that I referenced as well.
Lastly, if you don't have the root certificate setup, uncomment out the ServicePointManager line and add the following method. This will override any sort of certificate goofiness on your end.
And walla! You should be able to connect. Hope this helps someone.
Again, sorry about the code display. If you select and copy/paste the code will be much more readable.
First, in your config file (or in code I guess, my example is a config file), replace whatever was automatically generated for your security setting in your binding when you added the service with the following.
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
Next, you have to pass the username and password to the webservice. This I did in code, you can probably put the username and password in your config file somewhere as well. Here is a sample page_load method I did for a web page to do a test of the webservice.
Here are the namespaces that I referenced as well.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Security;
using System.Net;
using System.Security.Cryptography.X509Certificates;
protected void Page_Load ( object sender, EventArgs e )
{
//http://developers.de/blogs/damir_dobric/archive/2006/06/29/585.aspx
//ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback ( customXertificateValidation );
TheService.proxyname t = new TheService.proxyname ();
t.ClientCredentials.UserName.UserName = "someusername";
t.ClientCredentials.UserName.Password = "somepassword";
t.Open ();
try
{
Response.Write(t.SomeMethod ( "123456789", 123 ));
}
catch ( System.Exception ex )
{
Response.Write ( ex.ToString () );
}
finally
{
t.Close ();
}
Lastly, if you don't have the root certificate setup, uncomment out the ServicePointManager line and add the following method. This will override any sort of certificate goofiness on your end.
private static bool customXertificateValidation ( object sender,
X509Certificate cert, X509Chain chain,
System.Net.Security.SslPolicyErrors error )
{
return true;
}
And walla! You should be able to connect. Hope this helps someone.
Thursday, August 21, 2008
Very cool way of passing a DataSet to a WCF Service
Wanna generic WCF to consume any dataset you pass to it, and spit out a dataset on the other side?
I found this post, might get you started.
http://pstaev.blogspot.com/2008/04/passing-dataset-to-wcf-method.html
I found this post, might get you started.
http://pstaev.blogspot.com/2008/04/passing-dataset-to-wcf-method.html
Tuesday, August 19, 2008
Chucking Rocks at the Moon with WCF and NTLM Errors
So, I've been reading, studying, and toying mentally with WCF, but it was now time for me to do something with WCF.
So I created my "hello world" WCF service, and straight off the get go...problem.
I created my WCF web service (in an existing web app, going that route), left everything as default, and got the service running in debug mode. I copied default URL (with the ?wsdl) that comes up when you run the web service.
I then created a new web project, right clicked in VS 2008 on the Add Web Service, and pasted in the URL from above. The discovery took place, and everything looked good.
So in the code behind page_load method on my default page, I do something like this. Not your names will very.
then I fire it up...bomb. Something about an NTLM anonymous blah blah blah error.
I read, figure out you can turn NTLM off (if you are using Cassini, right click on your web application sln, properties, start up, uncheck NTLM). But that wasn't going to work as the web app that I'm adding the web service into actually needs NTLM.
So, I played around. By default, the binding used is wsHttpbinding. You can change that to get things running. In the web config on the web app that host the service, I changed the binding entry from wshttpbinding to basicHttpBinding. On my consumer web app, I updated the web service reference, then went into the web config and changed the security mode setting lines in the basicHttpBinding.
Well, once I fired up again in debug, everyting works, and allegidly NTLM is still in place. Hope this helps someone. Not sure how secure all this is, so I will keep playing.
So I created my "hello world" WCF service, and straight off the get go...problem.
I created my WCF web service (in an existing web app, going that route), left everything as default, and got the service running in debug mode. I copied default URL (with the ?wsdl) that comes up when you run the web service.
I then created a new web project, right clicked in VS 2008 on the Add Web Service, and pasted in the URL from above. The discovery took place, and everything looked good.
So in the code behind page_load method on my default page, I do something like this. Not your names will very.
ServiceReference1.WCFTestClient x =
new Consumer.ServiceReference1.WCFTestClient ();
try
{
Response.Write ( x.GetData ( 3 ) );
x.Close ();
}
catch ( System.Exception ex )
{
Response.Write ( ex.ToString () );
}
then I fire it up...bomb. Something about an NTLM anonymous blah blah blah error.
I read, figure out you can turn NTLM off (if you are using Cassini, right click on your web application sln, properties, start up, uncheck NTLM). But that wasn't going to work as the web app that I'm adding the web service into actually needs NTLM.
So, I played around. By default, the binding used is wsHttpbinding. You can change that to get things running. In the web config on the web app that host the service, I changed the binding entry from wshttpbinding to basicHttpBinding. On my consumer web app, I updated the web service reference, then went into the web config and changed the security mode setting lines in the basicHttpBinding.
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
Well, once I fired up again in debug, everyting works, and allegidly NTLM is still in place. Hope this helps someone. Not sure how secure all this is, so I will keep playing.
Monday, August 04, 2008
3 Important JSON / WCF Problems and Solutions
If you are using jQuery with .Net, you might want to check out the following post-
http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/
Encosia outlines three little items that could end up making you pull a lot of hair out of your head wondering why your JSON jQuery WCF communication isn't working
http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/
Encosia outlines three little items that could end up making you pull a lot of hair out of your head wondering why your JSON jQuery WCF communication isn't working
Labels:
Javascript,
Jquery,
WCF,
Web Development,
Web Services
Monday, June 02, 2008
Basic Asp.Net Javascript Invocation of a Web Service
Here is a Hello World example of a client side event calling a web service. The code will underlap the side bar, just copy and paste to get the full code.
A simple webform...
The actual Web Service (SimpleWebService.asmx)
Have fun.
A simple webform...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ServiceCallBackExample._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
//http://omensblog.blogspot.com/2007/07/aspnet-ajax-web-service-calls-from.html
//http://www.asp.net/learn/ajax-videos/video-79.aspx
//http://www.davidhayden.com/blog/dave/archive/2007/11/07/CallingWebServicesUsingClientSideASPNETAJAXServerSideValidation.aspx
function Button1_onclick() {
ret = ServiceCallBackExample.SimpleService.SayHello(document.getElementById('Text1').value, OnComplete, OnTimeOut, OnError);
return(true);
}
function OnComplete(arg) {
alert(arg);
}
function OnTimeOut(arg) {
alert("TimeOut encountered when calling Say Hello.");
}
function OnError(arg) {
alert("Error encountered when calling Say Hello.");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/SimpleService.asmx" />
</Services>
</asp:ScriptManager>
<br />
<div>
<input id="Text1" type="text" /><br />
<br />
<input id="Button1" style="width: 158px" type="button" value="button" language="javascript"
onclick="return Button1_onclick()" /> </div>
</form>
</body>
</html>
The actual Web Service (SimpleWebService.asmx)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
namespace ServiceCallBackExample
{
/// <summary>
/// Summary description for SimpleService
/// </summary>
[WebService ( Namespace = "http://tempuri.org/" )]
[WebServiceBinding ( ConformsTo = WsiProfiles.BasicProfile1_1 )]
[ToolboxItem ( false )]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class SimpleService : System.Web.Services.WebService
{
public SimpleService ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string SayHello ( String Name )
{
return "Hello : " + Name;
}
}
}
Have fun.
Subscribe to:
Posts (Atom)