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);
Related
I'm very new to web development but I wanted to create a web api for an existing Windows Service application I created for work.
My goal right now is to create a simple web app consisting of some text input fields where someone can enter their email and subscribe to a mailing list.
I was pointed in the direction of using OWIN to self-host a web api in my existing project so I looked at this guide to get started:
https://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api
This guide shows the console app calling and displaying the API, but I wanted to do the same from a web app. So I tried to do what is accomplished here in the 'Getting Started with ASP.NET Web Api 2' guide using a console application with OWIN.
When I start my console application, I can enter http://localhost:8080/api/values/1 and I get <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">value</string> Which I assume means the web server is running and responds to the request to get my string value that I'm returning from my ValuesController.
However I've been trying to create a simple web page that calls the API to get the value but I haven't been able to figure it out.
Right now my index.html has the following in the body:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
<script>
var uri = "http://localhost:8080/api/values/1";
$(document).ready(function () {
$.getJSON(uri)
.done(function (data) {
$('#value').text("done");
})
.fail(function (jqXHR, textStatus, err) {
$('#value').text('Error: ' + err);
});
});
</script>
And I just get Error: printed on the page. Again I'm new to working on web related technologies so any guidance would be much appreciated.
Ok so, following the discussion in comments (helping you to debug the app).
The cross-origin security policy in browsers restricts web pages from calling an data source that exists on a different domain. A domain is either a different url, or a different port at the same url.
http://localhost:80
is a different url/domain from:
http://localhost:81
There are two solutions to this, either utilise JSONP, or CORS to make the request to the api, JSONP basically wraps your json data up in a function call. When the api call returns, it executes the callback/function call, bypassing the security restriction.
However, both JSONP and CORS require server support, which brings solution 2...
Serve up the webpage you are trying to use from the API, meaning you server it from the same domain, hence no cross-domain issues!!
Glad you have got it sorted, I know it can be frustrating with web calls.
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.
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.
I am developing a c# desktop application and using a webservies which is developed in a php application when i try to consume that application. I just add web REference of that web service and try to access throught the following code
WebReference.TestWSDL pdl = new testingApp.WebReference.TestWSDL();
string copy = pdl.verify("testing");
it throws the error when i try to call the method verify. the error is
Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/.
and the web service link was like
http://171.139.101.12/code/index.php/webservice/wsdl
The error you are encountering is informing you that when you invoke the webservice, you are being given the WSDL (Web Service Definition Language) for the service - this is the metadata that describes the service functions, but cannot actually be used to invoke the service. Usually, you access the WSDL by appending either "?wsdl" or "wsdl" to the service URI.
There are two elements to the webservice you are attempting to consume.
The actual service exists at:
http://171.139.101.12/code/index.php/webservice
The metadata describing it, which Visual Studio via wsdl.exe used to generate a proxy, resides here:
http://171.139.101.12/code/index.php/webservice/wsdl
You need to edit the properties of the Web Reference and update the address appropriately. Alternatively, you can alter the properties of the pdl variable, and change the endpoint in code.
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";