02-21-2010 7:34 PM
Usually in my Office projects I use Web Reference in Visual Studio to connect to SAP.
Problem with Silverlight is that the option is not available in VS, and I can only use Service Reference, which just don't work.
What I do is:
- In SOAMANAGER create binding with user/pass login.
- Open WSDL for binding
- Paste WSDL in Add Service Reference.
Visual Studio can read the service, but then throws a lot of generation errors...and the reference doesn't work.
Can anybody use these type of Service Reference in VS with SAP?
Thanks.
EDIT: One error is "The endpoint X is not compatible with Silverlight 3"
02-21-2010 9:26 PM
04-22-2010 7:12 AM
Hi Sousa,
I am trying to access a webservice created in SAP system via silverlight 3 application. I do not get any errors but i am unable to see any output of the servicall cal. here are the steps i followed:
1. Created a class zcl_** and created a service in sicf under sap/bc and added the class as the handler.
2. i have written a short text message say "hello world" in the handle_request method of the handler class.
3. Now i create a simple silverlight 3 application in VS8 and add the following code under MainPage.xaml.cs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Net;
using System.Threading;
using System.Text;
namespace MySample1
{
public partial class MainPage : UserControl
{
public static ManualResetEvent allDone = new ManualResetEvent(false);
const int BUFFER_SIZE = 1024;
public MainPage()
{
InitializeComponent();
}
// The RequestState class passes data across async calls.
public class RequestState
{
const int BufferSize = 1024;
public StringBuilder RequestData;
public byte[] BufferRead;
public WebRequest Request;
public Stream ResponseStream;
// Create Decoder for appropriate enconding type.
public Decoder StreamDecode = Encoding.UTF8.GetDecoder();
public RequestState()
{
BufferRead = new byte[BufferSize];
RequestData = new StringBuilder(String.Empty);
Request = null;
ResponseStream = null;
}
}
private void getDataModel(object sender, RoutedEventArgs e)
{
System.Uri uri = new Uri("http://xxxx.xxx/sap/ztest_jvr?sap-client=000");
// Create the request object.
WebRequest wreq = WebRequest.Create(uri);
// Create the state object.
RequestState rs = new RequestState();
// Put the request into the state object so it can be passed around.
rs.Request = wreq;
// Issue the async request.
IAsyncResult r = (IAsyncResult)wreq.BeginGetResponse(
new AsyncCallback(RespCallback), rs);
// Wait until the ManualResetEvent is set so that the application
// does not exit until after the callback is called.
allDone.WaitOne();
DataModeltxt.Text = rs.RequestData.ToString();
}
private static void RespCallback(IAsyncResult ar)
{
// Get the RequestState object from the async result.
RequestState rs = (RequestState)ar.AsyncState;
// Get the WebRequest from RequestState.
WebRequest req = rs.Request;
// Call EndGetResponse, which produces the WebResponse object
// that came from the request issued above.
WebResponse resp = req.EndGetResponse(ar);
// Start reading data from the response stream.
Stream ResponseStream = resp.GetResponseStream();
// Store the response stream in RequestState to read
// the stream asynchronously.
rs.ResponseStream = ResponseStream;
// Pass rs.BufferRead to BeginRead. Read data into rs.BufferRead
IAsyncResult iarRead = ResponseStream.BeginRead(rs.BufferRead, 0,
BUFFER_SIZE, new AsyncCallback(ReadCallBack), rs);
}
private static void ReadCallBack(IAsyncResult asyncResult)
{
// Get the RequestState object from AsyncResult.
RequestState rs = (RequestState)asyncResult.AsyncState;
// Retrieve the ResponseStream that was set in RespCallback.
Stream responseStream = rs.ResponseStream;
// Read rs.BufferRead to verify that it contains data.
int read = responseStream.EndRead(asyncResult);
if (read > 0)
{
// Prepare a Char array buffer for converting to Unicode.
Char[] charBuffer = new Char[BUFFER_SIZE];
// Convert byte stream to Char array and then to String.
// len contains the number of characters converted to Unicode.
int len =
rs.StreamDecode.GetChars(rs.BufferRead, 0, read, charBuffer, 0);
String str = new String(charBuffer, 0, len);
// Append the recently read data to the RequestData stringbuilder
// object contained in RequestState.
//rs.RequestData.Append(
// Encoding.ASCII.GetString(rs.BufferRead, 0, read));
// Continue reading data until
// responseStream.EndRead returns u20131.
IAsyncResult ar = responseStream.BeginRead(
rs.BufferRead, 0, BUFFER_SIZE,
new AsyncCallback(ReadCallBack), rs);
}
else
{
if (rs.RequestData.Length > 0)
{
// Display data to the console.
string strContent;
strContent = rs.RequestData.ToString();
}
// Close down the response stream.
responseStream.Close();
// Set the ManualResetEvent so the main thread can exit.
allDone.Set();
}
return;
}
}
}
Under MainPage.xaml i have a simple code
<UserControl x:Class="MySample1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
<TextBlock x:Name="DataModelLbl" HorizontalAlignment="Center" Text="Data Model" Margin="5" Width="120" Height="30"/>
<TextBox x:Name="DataModeltxt" HorizontalAlignment="Right" Width="120" Height="30" />
<Button x:Name="myButton" HorizontalAlignment="Left" Content="Get Data Model" Click="getDataModel" Width="120" Height="30"/>
</Grid>
</UserControl>
Now i build the applicaion and run it.
The system hangs. or it doesnt get me any output/error.
Do you have any idea?
is there any steps i am missing?
Best Regards, JVR
I build the application and run it.
I get