<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>diploD &#187; guida</title>
	<atom:link href="http://www.diplod.it/tag/guida/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.diplod.it</link>
	<description>by Davide Del Monte</description>
	<lastBuildDate>Fri, 13 Feb 2015 14:26:10 +0000</lastBuildDate>
	<language>it-IT</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>Consumare un web service SAP con C#: guida pratica.</title>
		<link>http://www.diplod.it/2014/07/18/consumare-un-web-service-sap-con-c-guida-pratica/</link>
		<comments>http://www.diplod.it/2014/07/18/consumare-un-web-service-sap-con-c-guida-pratica/#comments</comments>
		<pubDate>Fri, 18 Jul 2014 10:24:06 +0000</pubDate>
		<dc:creator><![CDATA[Davide]]></dc:creator>
				<category><![CDATA[SAP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[abap]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[consumare]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[guida]]></category>
		<category><![CDATA[sap]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://www.diplod.it/?p=1443</guid>
		<description><![CDATA[Facciamola semplice, ad imperitura memoria per chiunque capiterà su queste pagine: ecco come consumare un web service SAP (ECC 6) con una applicazione web scritta in C#.]]></description>
				<content:encoded><![CDATA[<p>Facciamola semplice, ad imperitura memoria per chiunque capiterà su queste pagine: ecco come consumare un web service SAP (ECC 6) con una applicazione web scritta in <strong>C#</strong>.</p>
<p>Supponiamo di aver realizzato un <strong>function module</strong> in <strong>SAP</strong> semplicissimo: due parametri in ingresso (un numero e una stringa) e due parametri in uscita (lo stesso numero al quadrato e la stessa stringa).<br />
Di seguito il codice ABAP di tale funzione:</p>
<p><code>FUNCTION Z_TEST000.<br />
*"----------------------------------------------------------------------<br />
*"*"Interfaccia locale:<br />
*" IMPORTING<br />
*" VALUE(NUM) LIKE BAPISDHD1-DUN_COUNT DEFAULT 4<br />
*" VALUE(TEXTTEST) LIKE MARA-MATNR<br />
*" EXPORTING<br />
*" VALUE(RETURNNUM) LIKE BAPISDHD1-DUN_COUNT<br />
*" VALUE(RETURNCHAR) LIKE MARA-MATNR<br />
*"----------------------------------------------------------------------<br />
returnnum = num * num.<br />
returnchar = texttest.<br />
ENDFUNCTION.</code></p>
<p><span id="more-1443"></span>Supponiamo anche di averla <strong><a title="Pubblicare un function module SAP come web service" href="http://www.diplod.it/2013/11/20/sap-ecc-6-pubblicare-una-function-come-web-service-senza-fronzoli/" target="_blank">pubblicata come web service</a></strong>, in modo da avere l&#8217;indirizzo del <strong>WSDL</strong> per poter aggiungere il riferimento al servizio nella nostra soluzione di <strong>Visual Studio</strong>. Le indicazioni che <a title="Consumare web service sap" href="http://www.diplod.it/2012/10/26/consumare-un-web-service-sap-da-applicazione-net-in-c-visual-studio/" target="_blank">trovate qui</a>, per aggiungere il servizio in modo da poterlo utilizzare nel codice restano valide, in estrema sintesi: tasto destro sul nome della soluzione (il nodo root del nostro sito web) poi aggiungi.. -&gt; riferimento al servizio..</p>
<p>Nella maschera che appare basta mettere l&#8217;url del documento WSDL e dare un nome al servizio, che nel nostro caso è <strong>ztestoneee</strong>.</p>
<p>Questo il codice del front-end, una pagina in cui c&#8217;è solamente un pulsante che lancia un metodo per chiamare il web service e una label in cui visualizzeremo i risultati di questa chiamata.</p>
<p><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;<br />
&lt;head runat="server"&gt;<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;form id="form1" runat="server"&gt;<br />
&lt;div&gt;<br />
&lt;asp:Button ID="Button1" runat="server" Text="Vai bello!" OnClick="button_click" /&gt;<br />
&lt;asp:Label ID="Label1" runat="server" Text="incrocia le dita"&gt;&lt;/asp:Label&gt;<br />
&lt;/div&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p>A questo punto non resta che vedere il codice C# per consumare effettivamente il web service. Ci servono di fatto 3 oggetti:</p>
<ul>
<li>input: contiene i parametri da inviare al web service</li>
<li>client: è l&#8217;oggetto che esegue la chiamata</li>
<li>response: è l&#8217;oggetto che raccoglie la risposta dal web service</li>
</ul>
<p>Leggendo il codice sotto e i relativi commenti si può capire al volo il concetto.</p>
<p><code>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Globalization;<br />
<strong>using ztestoneee;</strong><br />
public partial class _Default : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
//al caricamento della pagina non succede nulla<br />
}<br />
protected void button_click(object sender, EventArgs e)<br />
{<br />
<strong>//inizializzo oggetti: input, client e response</strong><br />
ztestoneee.Z_TEST000 input = new ztestoneee.Z_TEST000();<br />
ztestoneee.ztestoneClient client = new ztestoneee.ztestoneClient();<br />
ztestoneee.Z_TEST000Response response = new ztestoneee.Z_TEST000Response();<br />
<strong>//inserisco valori da passare alla chiamata</strong><br />
input.NUM = 3;<br />
input.NUMSpecified = true;<br />
input.TEXTTEST = "Nice!";<br />
<strong>//chiamata a web service</strong><br />
response = client.Z_TEST000(input);<br />
<strong>//elaboro e pubblico la risposta</strong><br />
decimal returnnum = response.RETURNNUM;<br />
string returnchar = response.RETURNCHAR;<br />
Label1.Text = "Hey dude: " + returnnum + returnchar;<br />
}<br />
}</code></p>
<p>Il gioco è fatto.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.diplod.it/2014/07/18/consumare-un-web-service-sap-con-c-guida-pratica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
