cancel
Showing results for 
Search instead for 
Did you mean: 

Calling WEBService using MYSAPSSO2

Former Member
0 Kudos

Hi,

We would like to create a .NET application connected to our SAP CRM.

From the Portal I get MYSAPSSO2 cookie.

How to set up the CRM server to accept it?

We use portal to SSO, it works, but the webservice is not. Sends back 401 - not authorized.

We have CRM 6.20, NOT 6.40.

Regards,

Zoltán Károlyi

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member429661
Participant
0 Kudos

Hi Zoltan,

i know it's 4 year ago...but maybe somone limping over the same problem...

What i understand is, you want to consume a WebService on a CRM-System and before you have to authenticate on a Pportal-system. I have the same constellation. I use VS2015 as an Outlook AddIn, a Portal and a SRM Webservice.

Anyway... here is my solution:

1. Get the cookie MYSAPSSO2 out of the http-stream.


    Private Sub connect()

        Dim req As HttpWebRequest = HttpWebRequest.Create("http://xx-xx-xxx.prod.lokal:55000/irj/portal")

        Dim res As HttpWebResponse

        Dim strCookie As String

        req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0"

        req.Method = "GET"

        req.Credentials = CredentialCache.DefaultCredentials

        req.CookieContainer = New CookieContainer()

        Try

            res = req.GetResponse()

            strCookie = getMYSAPSSO2(res)

            oZBBP_PD_PO_GETDETAIL.setMYSAOSSO2 = strCookie

        Catch ex As Exception

            MsgBox(ex.Message.ToString)

        End Try

    End Sub

    Private Function getMYSAPSSO2(ByRef response As HttpWebResponse) As String

        Dim cook As Cookie

        Try

            For Each cook In response.Cookies

                If cook.Name = "MYSAPSSO2" Then

                    Return cook.Value

                End If

            Next cook

        Catch ex As Exception

            Return Nothing

        End Try

        Return Nothing

    End Function

Attention:
  • Use the HttpWebRequest/HttpWebResponse object... not the MSXML2 object(you dont get the cookie out of it)
  • set a CookieContainer on the request

2. Consume the WebService with the MYSAPSSO2 Cookie.


    Public Property getPODetail_HttpWeb() As String

        Set(value As String)

            Dim res As HttpWebResponse

            Dim sEnv As String

            sEnv = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:sap-com:document:sap:soap:functions:mc-style"">"

            sEnv = sEnv & "<soapenv:Header/>"

            sEnv = sEnv & "<soapenv:Body>"

            sEnv = sEnv & "<urn:BbpPdPoGetdetail>"

            sEnv = sEnv & "<IObjectId>" & value & "</IObjectId>"

            sEnv = sEnv & "</urn:BbpPdPoGetdetail>"

            sEnv = sEnv & "</soapenv:Body>"

            sEnv = sEnv & "</soapenv:Envelope>"

            Dim req As HttpWebRequest = HttpWebRequest.Create(e71_URL)

            Dim strCokkie As String = "cookie: MYSAPSSO2=" & MYSAPSSO2

            With req

                Try

                    .Headers.Add("Accept-Encoding:gzip,deflate")

                    .Headers.Add("SOAPAction:Retrieve")

                    .Headers.Add(strCokkie)

                    .Method = "POST"

                    .Credentials = CredentialCache.DefaultCredentials

                    .UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0"

                    .Host = "xx-xx-xxx.prod.lokal:8096"

                    .ContentType = "text/xml;charset=UTF-8"

                    Dim newStream As New StreamWriter(.GetRequestStream(), Encoding.UTF8)

                    newStream.Write(sEnv)

                    newStream.Flush()

                    newStream.Close()

                    res = .GetResponse()

                    Dim sr As StreamReader

                    Dim strResult As String = ""

                    Dim streamStream As Stream

                    streamStream = res.GetResponseStream()

                    streamStream = New GZipStream(streamStream, CompressionMode.Decompress)

                    sr = New StreamReader(streamStream, Encoding.UTF8)

                    strResult = sr.ReadToEnd.Trim

                    sr.Close()

                    document.LoadXml(strResult)

                    req = Nothing

                Catch ex As Exception

                    MsgBox(ex.Message.ToString)

                End Try

            End With

            req = Nothing

        End Set

        Get

            Return Nothing

        End Get

    End Property

Attention:
  • set the default credentials
  • you have to decode the response stream

be happy...

--Bernward

Former Member
0 Kudos

Hi,

Sorry, but I misstyped version. We have BBPCRM 4.0:

SAP_BASIS 620 0054 SAPKB62054

SAP_ABA 620 0054 SAPKA62054

BBPCRM 400 0008 SAPKU40008

PI_BASIS 2006_1_620 0001 SAPKIPYK01

ST-PI 2005_1_620 0007 SAPKITLQG7

ST-A/PI 01J_CRM400 0000 -

VIRSANH 520_620 0009 SAPK-52109INVIRSANH

The SSO is working using portal links after I log into the portal.

If I try to use a function through WebService, providing the MYSAPSSO2 cookie -> it fails.

Regards,

Zoltán Károlyi

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Zoltan,

this is described in the SAP Online Help for the SAP Web Application Server 6.20.

http://help.sap.com/saphelp_webas630/helpdata/en/eb/ef683c25e9096de10000000a114084/frameset.htm

Best regards,

André