Showing posts with label Web Services. Show all posts
Showing posts with label Web Services. Show all posts

Monday, May 11, 2015

Debugging Old ASMX Web Services - The "Cannot Create Type XXX" Error

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.

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.

Thursday, June 24, 2010

Tip On Web Service Engineering

On my last project, I'm sending data back to a client. The client is taking the data and updating several internal systems before acknowledging the data is received by sending me back a success code.

This is causing me all sorts of head aches. Their internal systems a slow, and I'm getting some strange errors. I upped the timeout to 10 minutes even, and still no love.

So, some advice. Just pass data to a store. Have your clients and yourself do their processing on that data outside of the web service. This will speed things up quiet a bit and help narrow down issues, and avoid timeouts ;)

If need by, you can setup your status's something like this.

  • Data Sent but Save Failed.
  • Data Sent Successfully.
  • Data Processing Failure.
  • Data Process Success.

Wednesday, February 24, 2010

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

Sunday, November 02, 2008

Saving XML to SQL and the Dreaded Parse Error

I recently at work tried to save an XML string to SQL Server 2005 and I kept getting the following error...

XML parsing: line 1, character 38, unable to switch the encoding

Turns out the solution was to just change the paramter datatype that I'm passing to the stored proc to a varchar (even though the stored proc expects XML) and the problem goes away and data is saved fine. Example of the parameter I passed to the stored proc-


SqlParameter p_xml = new SqlParameter ();
p_xml.ParameterName = "@p_xml";
p_xml.SqlDbType = SqlDbType.VarChar;
p_xml.Value = "your xml string";


The issue has to do with my string XML being UTF-8 based, and SQL 2005 wanting UTF-16. The above hack fixes the issue, and you can still pass UTF-16 based XML and the varchar handles that as well.

Credit for the fix goes to Bob Beauchemin at this link-

http://bytes.com/forum/thread498342.html

Monday, October 27, 2008

soapUI: Nice Web Service Testing Tool

In my saga of abandoning WCF and regressing back to an ASMX web service for a current project I had a very knowledgable web service person from a telecommunications company send me an invaluable tool for testing webservices.

http://www.soapui.org/

The cool thing is you can mock web service request, or even send soap request to a webservice through soapUI. The tool has a gazillion features that I haven't even scrated the surface of yet.

I highly recommend it. At first you will open it up, be a little bummed that it is written in JAVA, and you will come to an inteface without knowing really how to proceed. Download a WSDL from a web service and save it, then in soapUI create a new WSDL project and load your local version of the WSDL. You will see how valuable the tool can be.

There is a Pro version with more features, though I haven't checked that out.

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.

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).

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.



  <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

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.

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

Tuesday, July 01, 2008

Bad @ss, TCP/IP from a Web Browser in JavaScript

Welcome to the world of "Comet" servers. What is a Comet server? A Comet server is a server that supports communicating via TCP and other protocols directly to and from a web server from a web browser using client side Javascript. Typically you could enable doing this by using a Java applet or a Flash object, but javascript I guess has matured enough to the point where this can be done, in theory, without the use of external plugins.

Read on [HERE] for more info about Comet servers.

Below is a great comet server called Orbital that is open source, plays well with both IIS and Apache, and is easy to use. Read about it here-

http://cometdaily.com/2008/07/01/sockets-in-the-browser/

Here is just a taste of how easy it is to use (allegedly, I haven't installed it yet)-

var conn = new TCPSocket(hostname, port)
conn.onopen = function() { alert('connection opened!') }
conn.onread = function(data) { alert('RECEIVE: ' + data) }
conn.onclose = function(data) { alert('connection closed!') }
conn.send('Hello World');

Wow. Chat. MMO's. Ditching bloated complex web services as a means of communication. If Orbital works as advertised, I see whole new worlds opening up.

Orbital's website is here-

http://orbited.org/

I found this post on Ajaxian, an excellent blog well worth an RSS subscription-

http://ajaxian.com/archives/tcpsocket-sockets-in-the-browser

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...

<%@ 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()" />&nbsp;</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.