Problem passing parameters to WebService asp-net C# - c#

Hi everyone let me explain this issue:
Background:
I have two web applications
The first one exposes some web services (server_wapp).
The second one consumes them (client_wapp).
I added a new web service to the server application that takes two strings as parameters, and it work OK using it directly form the .asmx page (new_ws).
Problem:
When I call the new_ws from the client_wapp all the parameters have their right content, but when the method is executed in the server_wapp, one of its parameters is passed as null.
Somthing link this:
In client_wapp I have server_wapp.new_ws("string1", "string2") and it gets executed in server_wapp as new_ws("string1", null).
I already rebuilt both web applications, but the problem remains.
Any ideas/comments?
Thanks in advance!

Update the link to server_wapp so that the proxy source code will be re-generated. WebService is usually used by adding reference to webservice url, and everytime you do some modifications in the webservice, its should be updated.

Related

IndexOutOfRangeException when creating an Extension Codeunit for a Page Web Service

I'm trying to expose a Function in a Codeunit through a Page Web Service in Dynamics NAV (2009 R2). I followed the MSDN documentation and the steps in a blog post, but I'm getting the following error when connecting to the Web Service:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
I've created a Page Web Service and a Codeunit Web Service, both using the same name, with only the Page Web Service published:
My Codeunit contains only 1 Function for the moment and looks like this:
When I publish the Codeunit Web Service as well, I can use it, but the Page Web Service still shows the error.
When I rename the Codeunit Web Service, the Page Web Service works again as before, without the Codeunit's Functions, of course.
Am I missing something or doing something wrong?
Function in your codeunit have wrong signature. Moreover in the blog it is Run function that is used (not user function). Don't know if it's matters.
Next phase: post the selected invoice. I don't have a method in my web service to post my invoice, so this is where we are going to extend the web service with this possibility. Very simple! I just created a codeunit with a function. In this function, the signature is important: the first parameter should be the same record variable of the page you published (in our case, "Sales Header"). This is my (only) function of my codeunit:
PostInvoice(precSalesinvoice : Record "Sales Header")
CODEUNIT.RUN(CODEUNIT::"Sales-Post", precSalesinvoice);

C# Calling Web Services to different URLs

I'm new to Web Services from C#, but have worked C# for years, just never needed to use Web Services. Due to privacy issues, I can't disclose actual URL, but there is a test server and a production server where the web services are identical in all other respects, and the services were written / managed by another entity.
https://LiveSite.SomeDomain.com/FolderInWebSite/TestWebServiceSoapHTTP
and
https://TestSite.SomeDomain.com/FolderInWebSite/TestWebServiceSoapHTTP
Do I need to create two separate web references to the project and create different instances of them to go, or can I via some property just change which URL version it is sending data to.
Additionally, not being familiar working web services, I see the classes as Visual Studio imported. I can create instances of the classes and set the applicable properties (int, dates, strings, string[] arrays, etc). But not seeing how to actually say ... Go send it now. and then getting the response back.
I've done this from an older application with another language and was doing direct with HTTP and SOAP where I was able to make my own connection to the URL, build the body of the SOAP message, then send it.
Just use the "Url" property.
var myProxy = new MyProxy();
myProxy.Url = "http://foo.com/myservice";
Edit for second part of the question:
There should be a method for each action exposed the API that you can call. For example if the API exposes a MyAction that takes a string, the code generator should have generated a method that you can use like so:
myProxy.MyAction("hello");

SOAP Request and Response with ASP.NET using the WSDL URL As Web Service?

Ok, installed Visual Web Developer 2008, Created a Website as ASP.net (C# Language), than added a Service to it via the following URL: http://ws.idssasp.com/members.asmx?wsdl and after hitting Go, looks like this (I change the namespace to ServiceMembers):
Now it looks like this:
If I than go to Default.aspx.cs file, How do I use this on Page Load? I want something to be outputted from the Service on Page Load, ofcourse, will need to call something else via a button, but really just need a way to get anything from this service to be outputted... How to do this?
Looking here: http://ws.idssasp.com/members.asmx there are a bunch of methods that resemble the pic above, but how to use them anywhere? When I try to do Response.Write(ServiceMembers.GetCategoryListResponse); if gives error that this is a Type and can not be used in that way. How do I use anything here?
Also, I will need to pass a Username and Password into the initial SOAP POST to that URL (which I have), before I can get anything back as a Response, but how? Looks like I should use ServiceMembers.AuthorizeHeader somehow? But how? Looking at the Request XML from this page here for GetCategoryList, has this listed in the XML:
<soap:Header>
<AuthorizeHeader xmlns="http://ws.idssasp.com/Members.asmx">
<UserName>string</UserName>
<Password>string</Password>
</AuthorizeHeader>
</soap:Header>
But how to do this via code to the server? Unknown!
I don't see GetCategoryList Method as an option for ServiceMembers namespace anywhere, but there is GetCategoryListRequest Type and GetCategoryListResponse Type as options for ServiceMembers via the last pic. How do I invoke Methods of a Service? How do I use any of this for this step in the process? I have read so many tutorials on this, but nothing that I've seen explains how to do this without error of some sort, or different situations than mine.
Can anyone start me out with just simple code on outputting anything from this Web Service? Anything at all? Everyone is saying to use Visual Web Developer as it will do the Bulk of the work for you, but no one is explaining how to use any Web Service that you install. Seems that they only explain on how to use Specific things in Web Services, it's like they aren't teaching you to fish in an ocean of fish, but instead setting you up to fail, with a fish in a bucket that you are sure to catch.
What is the next step here? I didn't create this Web Service, and I don't know how to use it in the ASP.NET Website either.
The GetCategoryList method is in MembersSoapClient class and you need to create an instance of MembersSoapClient to use GetCategoryList. Try this in your Page_Load method:
protected void Page_Load(object sender, EventArgs e)
{
AuthorizeHeader authorizeHeader = new AuthorizeHeader();
authorizeHeader.UserName = "yourusername";
authorizeHeader.Password = "yourpassword";
MembersSoapClient client = new MembersSoapClient();
Category[] categories = client.GetCategoryList(authorizeHeader);
}

How to use web service methods in ssrs?

I am new to the SSRS i have created a web service which has one method which takes the string value and returns image of bar-code of that value method is as below
Image BarcodeText(string textToBarcode,int barcodeWeight,bool isMargin)
i want to call this method in my SSRS report from the web service in the image box expression and pass the value to the method i don't know how to call a method from the web service. I searched for accessing method from the web service but came up as no help so any links or any description would really helpful for,
1) How to reference web service in the report ?
2) How to call method from web service and pass the parameters to the method ?
Thanks in advance.
I have got same problem some time back so i got a work around for this problem i hope this will work for you too.
1) First i created the web app with the service reference of the created web service suppose Barcode39 is service so add the reference to the web application.
2) Then write the code behind using service client and call the method to create the barcode image in that code by passing the request variables values
3) Now give the link of that page as the URL to the image expression along with setting the image type as "EXTERNAL" and pass the values to the URL as request variables as
"http:\\localhost:2310\BarcodeImage.aspx?data=" +(Parameters!YourParamtere.Value)
And one thing instead of returning the Image from the service try returning the byte array using stream and .ToArray() method that would be the best practice.Let me know if any problem.
http://technet.microsoft.com/en-us/library/aa964129.aspx
This webpage give you all the info you need for accessing web service from SSRS.

C# SOAP with a custom URL

Okay, simple situation: I'm writing a simple console application which connects to a SOAP web service. I've imported a SOAP Service reference and as a result, my application has a default endpoint build into it's app.config file.
The web service, however, can run on multiple servers and the URL to the proper web service is passed through the commandline parameters of my application. I can read the URL, but how do I connect the web service to this custom URL?
(It should be very simple, in my opinion. It's something I'm overlooking.)
Is this using an auto-generated class deriving from SoapHttpClientProtocol? If so, just set the Url property when you create an instance of the class.
Well, .NET can provide some very useless error messages sometimes. In IIS, the service was configured to AutoDetect cookieless mode. As a result, I had to append "?AspxAutoDetectCookieSupport=1" to the URL. Although that would fix the problem, it was just easier to go to the IIS console, open the properties of the service, go to the ASP.NET tab page, click the "Edit configuration" button, to to "State Management" in the newly popped up screen and change "Cookieless mode" into something other than "AutoDetect"...
Excuse me. Dumb error. Am going to hit myself on the head a few times for this. ;-)
As Jon said, you set the Url, as in:
Namespace.ClassName nwe = new Namespace.ClassName();
nwe.Url = "http://localhost/MyURL/site.asmx";

Categories