Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Wednesday, March 28, 2012

Consuming services from another application with Cassini

I have two projects in a solution: a Web Application (UI) project and a Web Service project. I can't get the UI to consume a web service if the projects are running using the built-in web server. My OnCompleted or OnError callbacks never get called. However, it works if I use IIS.

So the client ishttp://localhost:4312/default.aspx and it references the service using:

<atlas:ServiceReferencePath="http://localhost:1234/Service1.asmx"/>

If all I do is make them both IIS apps then change the reference as follows, it works a treat:

<atlas:ServiceReferencePath="/ServiceApp/Service1.asmx"/>

Is this because Cassini's use of different port numbers makes this appear as a forbidden cross-domain call?

BTW, I obviously made sure that Cassini was listening on both ports.

If the port's not the same yes you will get a crossdomain error.

But I don't think that's the only issue. Cassini listens to a specific port and sets up the ASP.NET runtime for a specific virtual directory. 1 port, 1 Virtual directory, 1 instance of Cassini.So unless youhave two separate instenaces of Cassini running the call won't work because it's effectively only servicing a single application. You'll need two instances of VS or Cassini to make this happen and I don't think you can do that either because only one instance can listen on a given port.

So, no you probably can't do that <s>... Use IIS and separate virtuals.

+++ Rick --


Yeah, thanks Rick. That's pretty much the conclusion I've come to. But I find it strange that the port is considered part of the domain. Cool blog by the way.

Stu

Consuming a webservice from a custom control extender

I am making a first attempt at writing own extender using the toolkit, and I need to consume a web service. When I Google on Ajax and webservice, I get a lot of articles, but they all seem to involve modifying the ScriptManager tag to point to the web service I want, and you can't rely on that from an extender paradigm. I know the autocomplete control uses some sort of web service, but picking the code out is tough. Is there a plain vanilla, Hello World type of example of how to consume a web service from a custom control extender?

There seems to be a couple of ways to do this, check this post:

http://forums.asp.net/t/1163304.aspx

Although I like mine betterSmile

Hope this helps,

Elias.


Thanks Elias, that's what I was looking for.

connection to Web Service Refused

I created a simple webservice on my local system. I then created the proxy on the command line (Services.cs).
I wrote a Console App to use the webservices. Added a reference to System.Web.Services And did a right click Add --> Existing Item --> Services.cs

Anonymous Access is set on IIS.

The failure I get is:
Unhandled Exception: System.Net.WebException: Unable to connect to the remote server --> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.

I tried setting (in the WebService) Dynamic Port to false. After I did this, it worked the first time, but since then has the same error as above.

OS: Windows XP Pro

Any thoughts would be appreciated.

Thanks, Jason

It might be worth while posting this in the Web services or WCF forums

.NET 2.0 ASMX Web Services: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=46&SiteID=1

WCF: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=118&SiteID=1


Thanks, i will do that.

J

Monday, March 26, 2012

Connect to a web reference

I have a web service running on my local machine and I have added it to a Atlas project in Visual Studio using web reference. There are three files created under App_WebReferences\localhost: xxx.disco, xxx.discomap and xxx.wsdl. How should I reference it in the following Atlas tag:

<atlas:servicereferencepath="??"type="text/javascript"/>

Also in my web service code, it has the following line:

<%@dotnet.itags.org. WebService Language="c#" Codebehind="ServerStatus.asmx.cs" Class="Microsoft.TeamFoundation.Server.ServerStatus" %>

But when I use the methodMicrosoft.TeamFoundation.Server.ServerStatus.GetSupportedContractVersion, I get an error saying "Microsoft" is undefined.

In general the service code is not available. I suppose its class information should be in .wsdl file. But I am not sure where to locate it. Please help. Thanks.

I had the same problem. You are not able to call external webservices by importing a web reference. You need to wrap the external webservice in your own webservice implemented by an asmx file.
For this I created a C# library with Visual Studio and added a web reference in the library. Now I was able to add a reference to the reulting DLL and call the external webservice from MyWebservice.asmx.
You are obligate to use this solution when the webservice is located on a different server than where your website will be hosted, because Javascript can not make HTTP requests to other servers.
Maybe you can bridge to that particular external web service. I am currently reading the followinghttp://atlas.asp.net/docs/atlas/doc/bridge/default.aspx.

Saturday, March 24, 2012

Configuration Error System.Web.Extensions

Configuration Error

Description:An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message:Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. (D:\Web_Sites\Arctic\aid-0173\web.config line 39)

Source Error:

Line 37: </httpHandlers>Line 38: <httpModules>Line 39: <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>Line 40: Line 41: </httpModules>

Here is the error we are getting? The application works fine on our local computers, what is causing this? Please, don't tell us we have to have our IT department install anything on the servers either.

I am about to answer my own post in record time!

I have the solution for you!

Get the following dlls from

C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

AJAXExtensionsToolbox.dll

System.Web.Extensions.dll

System.Web.Extensions.Design.dll

Once you have done that make sure you have the following files in your bin.

They came with the new install of AJAX.

Also we have to make sure that in our web.config under assemblies the PublicKeyToken portion is all Caps!

Good

PublicKeyToken=31BF3856AD364E35

Bad

PublicKeyToken=31bf3856ad364e35

We did this and are up and running now on our production server!

If you can run in full trust, then you can copy the binaries to the /bin directory.

Otherwise, yes, you will need to have the IT department install on the servers. (This is very much preferred... it allows for things like security patches to get to you via Windows Update.)


Thank you so much! Your suggestion solved my problem.

Conditional Logic in the Web Service that feeds the AutoComplete extender ? ?

I have a Autocomplete extender that is "tied" to a web service ... the web service basically populates an array of folder names in a directory (these folder names also happen to be server names)

It works great, I get a full list of folder names (servers) with the following code (this is a chunk of the relevant code) ... However I need any of the "If" statements to work, but when I use these, I get nothing when I press keys ... i.e. known folder names

GetServerNames.vb

==============

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.IO.Directory

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class GetServerNames
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function ReturnServerFolders(ByVal prefixText As String, ByVal count As Integer) As String()
Dim strFolderPath As String = ("C:\SERVER_FILES\")
Dim arrDirectories As String() = System.IO.Directory.GetDirectories(strFolderPath)
Dim strDirectory As String
Dim items As New List(Of String)
For Each strDirectory In arrDirectories
strDirectory = Replace(strDirectory, strFolderPath, "")
'If prefixText = Left(strDirectory, prefixText.Length) Then '<- does not work returns no names
'If strDirectory.StartsWith(prefixText) Then '<- does not work returns no names
'If InStr(strDirectory, prefixText) Then '<- does not work returns no names
items.Add(strDirectory) '<- works always with no if logic returns all folder names
'End If
Next
Return items.ToArray()
End Function

End Class

Default.aspx

=========

<asp:TextBoxID="TextBox1"runat="server"Width="130px"></asp:TextBox>

<cc1:AutoCompleteExtenderID="AutoCompleteExtender1"runat="server"TargetControlID="TextBox1"

ServicePath="GetServerNames.asmx"ServiceMethod="ReturnServerFolders"

MinimumPrefixLength="2"CompletionSetCount="20"CompletionInterval="1000"

EnableCaching="true"Enabled="true">

</cc1:AutoCompleteExtender>

Maybe it's just a case (!) of case sensitivity.

If strDirectory.StartsWith(prefixText, StringComparison.InvariantCultureIgnoreCase)


Yep, Thanks

That is it ...

Actually the lightbulb went off when I saw this post

http://support.jodohost.com/archive/index.php?t-9497.html

I was coming back here to post a "solved" ... I knew when I saw a reply that would be it ;-)

I am going to go with the InStr function because this field is actually a "Server Name" field ... this could be helpful if looking for a server name with "WEB" in it regardless of what it begins with.

Here is the working ServiceMethod for this

===============================

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.IO.Directory

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class GetServerNames
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function ReturnServerFolders(ByVal prefixText As String, ByVal count As Integer) As String()
Dim strFolderPath As String = ("C:\SERVER_FILES\")
Dim arrDirectories As String() = System.IO.Directory.GetDirectories(strFolderPath)
Dim strDirectory As String
Dim items As New List(Of String)
For Each strDirectory In arrDirectories
strDirectory = Replace(strDirectory, strFolderPath, "")
If InStr(Ucase(strDirectory), Ucase(prefixText)) Then
items.Add(strDirectory)
End If
Next
Return items.ToArray()
End Function

End Class

Wednesday, March 21, 2012

Concurrency and EnableSession

Hi all.
I'm writing a web service to return data to a web page that use ajax to manage it.

I use the property EnableSession in WebMethod to enable the session and manage my authenticated user.

The problem is that my web service doesn't handle concurrent request and queue them.


Is there a way to make them concurrently?!

Thanks in advance.
Stefano

It is probably my two requests try to access to the same session object and cannot do it.

But this is what i wanna do!

Is there a workaround??

Thanks
Stefano


Solved it myself.

I created a application variable hashtable in wich i store SessionId and the id of the current logged in user.
In every web method i pass one new parameter that is SessionId.

Bye!
Stefano